Skip to content

Commit 503b089

Browse files
committed
net: don't throw on immediately destroyed socket
Fixes regression introduced in af249fa. With connect being deferred to the next tick, Socket.destroy could be called before connect. Socket.destroy sets _connecting to false which would cause an assertion error. Fixes: #2250 PR-URL: #2251 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent 2ca5a3d commit 503b089

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/net.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,8 @@ function lookupAndConnect(self, options) {
927927
var addressType = exports.isIP(host);
928928
if (addressType) {
929929
process.nextTick(function() {
930-
connect(self, host, port, addressType, localAddress, localPort);
930+
if (self._connecting)
931+
connect(self, host, port, addressType, localAddress, localPort);
931932
});
932933
return;
933934
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const net = require('net');
5+
6+
const socket = net.connect(common.PORT, common.localhostIPv4, assert.fail);
7+
socket.on('error', assert.fail);
8+
socket.destroy();

0 commit comments

Comments
 (0)