From f3530809a28b794778cde64de6ae1ef7daa53361 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 26 Jul 2015 20:28:00 -0400 Subject: [PATCH] net: don't throw when socket is destroyed --- lib/net.js | 4 +++- test/parallel/test-net-socket-destroy-immediately.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-net-socket-destroy-immediately.js diff --git a/lib/net.js b/lib/net.js index b5ae15e4692393..44087e76c91801 100644 --- a/lib/net.js +++ b/lib/net.js @@ -927,7 +927,9 @@ function lookupAndConnect(self, options) { var addressType = exports.isIP(host); if (addressType) { process.nextTick(function() { - connect(self, host, port, addressType, localAddress, localPort); + // Verify that the socket wasn't destroyed already + if (self._connecting) + connect(self, host, port, addressType, localAddress, localPort); }); return; } diff --git a/test/parallel/test-net-socket-destroy-immediately.js b/test/parallel/test-net-socket-destroy-immediately.js new file mode 100644 index 00000000000000..b606edbfe01519 --- /dev/null +++ b/test/parallel/test-net-socket-destroy-immediately.js @@ -0,0 +1,12 @@ +'use strict'; +var common = require('../common'); +var assert = require('assert'); +var net = require('net'); + +var socket = net.createConnection(common.PORT, common.localhostIPv4); + +socket.on('error', function(err) { + assert(false); +}); + +socket.destroy();