Skip to content

Commit

Permalink
net: don't throw on immediately destroyed socket
Browse files Browse the repository at this point in the history
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 <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
evanlucas committed Jul 27, 2015
1 parent 2ca5a3d commit 503b089
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,8 @@ function lookupAndConnect(self, options) {
var addressType = exports.isIP(host);
if (addressType) {
process.nextTick(function() {
connect(self, host, port, addressType, localAddress, localPort);
if (self._connecting)
connect(self, host, port, addressType, localAddress, localPort);
});
return;
}
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-net-connect-immediate-destroy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');

const socket = net.connect(common.PORT, common.localhostIPv4, assert.fail);
socket.on('error', assert.fail);
socket.destroy();

0 comments on commit 503b089

Please sign in to comment.