Open Bug 784022 Opened 12 years ago Updated 2 years ago

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

Categories

(Core :: Networking, defect, P5)

defect

Tracking

()

People

(Reporter: glandium, Unassigned)

Details

(Whiteboard: [necko-would-take])

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.
The same behaviour can be observed when the connection is in SYN_SENT status, when the target host doesn't respond.
(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
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.