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.
  • Loading branch information
ronag committed Oct 1, 2019
1 parent f663b31 commit 2b81112
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 2b81112

Please sign in to comment.