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.
Bulk change to priority: https://bugzilla.mozilla.org/show_bug.cgi?id=1399258