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 <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
1 parent 20896f7 commit 65c4752

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎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+
constcommon=require('../common');
3+
constnet=require('net');
4+
5+
constsocket=newnet.Socket();
6+
socket.on('close',common.mustCall());
7+
socket.destroy();

0 commit comments

Comments
 (0)