Skip to content

Commit 65c4752

Browse files
ronagBridgeAR
authored andcommitted
net: emit close on unconnected socket
Socket should always emit 'close'. Regardless whether it has been connected or not. PR-URL: #29803 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent 20896f7 commit 65c4752

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/net.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,10 +660,12 @@ Socket.prototype._destroy = function(exception, cb) {
660660
this._handle.onread = noop;
661661
this._handle = null;
662662
this._sockname = null;
663+
cb(exception);
664+
} else {
665+
cb(exception);
666+
process.nextTick(emitCloseNT, this);
663667
}
664668

665-
cb(exception);
666-
667669
if (this._server) {
668670
debug('has server');
669671
this._server._connections--;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
const common = require('../common');
3+
const net = require('net');
4+
5+
const socket = new net.Socket();
6+
socket.on('close', common.mustCall());
7+
socket.destroy();

0 commit comments

Comments
 (0)