From af249fa8a15bad8996187e73b480b30dcd881bad Mon Sep 17 00:00:00 2001 From: Evan Lucas Date: Thu, 25 Jun 2015 06:41:10 -0500 Subject: [PATCH] net: wrap connect in nextTick MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes an edge case regression introduced in 1bef71747678c19c7214048de5b9e3848889248d. With the lookup being skipped, an error could be emitted before an error listener has been added. An example of this was presented by changing the server’s IP address and then immediately making a request to the old address. Related: https://github.com/nodejs/io.js/pull/1823 PR-URL: https://github.com/nodejs/io.js/pull/2054 Reviewed-By: Colin Ihrig Reviewed-by: Trevor Norris --- lib/net.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/net.js b/lib/net.js index 4c5e62b58c09e4..5a429a244f49f5 100644 --- a/lib/net.js +++ b/lib/net.js @@ -925,7 +925,9 @@ function lookupAndConnect(self, options) { // TODO(evanlucas) should we hot path this for localhost? var addressType = exports.isIP(host); if (addressType) { - connect(self, host, port, addressType, localAddress, localPort); + process.nextTick(function() { + connect(self, host, port, addressType, localAddress, localPort); + }); return; }