The output stream handed by socket-transport-service's transports don't report any error when the socket couldn't be opened

NEW
Unassigned

Status

()

Core
Networking
P5
normal
5 years ago
2 months ago

People

(Reporter: glandium, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [necko-would-take])

(Reporter)

Description

5 years ago
Copy/paste the following in Scratchpad, in browser environment (with nothing listening on port 4242), and press Ctrl+L (display):
sts = Cc['@mozilla.org/network/socket-transport-service;1'].getService(Ci.nsISocketTransportService);
transport = sts.createTransport(null, 0, 'localhost', 4242, null);
output = transport.openOutputStream(0, 0, 0);
output.write("foo", 3);

The value the last function returns is ... 3, while the connection didn't open.

Changing openOutputStream flags (first argument) to 2 (UNBUFFERED) makes write throw a NS_BASE_STREAM_WOULD_BLOCK exception.

Neither are really helpful.

Fortunately, doing transport.openInputStream(0, 0, 0).available() throws a NS_ERROR_CONNECTION_REFUSED exception, but theoretically, you could very well have one half of the connection closed, and still be unable to detect the situation.
(Reporter)

Comment 1

5 years ago
The same behaviour can be observed when the connection is in SYN_SENT status, when the target host doesn't respond.
(Reporter)

Comment 2

5 years ago
(In reply to Mike Hommey [:glandium] from comment #0)
> Fortunately, doing transport.openInputStream(0, 0, 0).available() throws a
> NS_ERROR_CONNECTION_REFUSED exception

Actually, it does on aurora, but doesn't on nightly. On nightly it gives me either 0 or undefined.
Whiteboard: [necko-would-take]
Bulk change to priority: https://bugzilla.mozilla.org/show_bug.cgi?id=1399258
Priority: -- → P5
You need to log in before you can comment on or make changes to this bug.