Skip to content

Commit

Permalink
net: emit close on unconnected socket
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ronag authored and BridgeAR committed Oct 9, 2019
1 parent 20896f7 commit 65c4752
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,12 @@ Socket.prototype._destroy = function(exception, cb) {
this._handle.onread = noop;
this._handle = null;
this._sockname = null;
cb(exception);
} else {
cb(exception);
process.nextTick(emitCloseNT, this);
}

cb(exception);

if (this._server) {
debug('has server');
this._server._connections--;
Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-net-connect-destroy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';
const common = require('../common');
const net = require('net');

const socket = new net.Socket();
socket.on('close', common.mustCall());
socket.destroy();

0 comments on commit 65c4752

Please sign in to comment.