socket: don't emit premature 'close'
I'm not sure how to get this to work properly nor how to create a test for it but I think there is an issue here to fix.
Looking at the current net.Socket
implementation I see a few potential problems:
-
'close'
can be emitted twice. Once from https://github.com/nodejs/node/blob/master/lib/net.js#L597 and once from https://github.com/nodejs/node/blob/master/lib/net.js#L604. Once withhadError
argument and once without. -
EDIT: Doesn't emit
close
if!_handle
. -
EDIT:
_server._emitCloseIfDrained
before socket is closed. -
'close'
can be prematurely emitted before the handle is actually closed. -
'close'
has an argument which doesn't conform with the streams spec. -
if the handle calls the callback synchronously then'close'
is emitted whiledestroyed !== false
. -
Some user land code expect
'close'
to have no arguments, e.g.
function onComplete (err) {
if (err) {
...
} else {
...
}
}
socket.on('error', onComplete)
socket.on('close', onComplete)
Also, I believe the spec for stream events says that 'close'
has no arguments?
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines