From 4e204f37fd994b3bd11a829c9f6938b5a3ca9774 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 12 Aug 2011 15:42:45 +0200 Subject: [PATCH] net: defer DNS lookup error events to next tick net.createConnection() creates a net.Socket object and immediately calls net.Socket.connect() on it. There are no event listeners registered yet so defer the error event to the next tick. Fixes #1202. --- lib/net.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/net.js b/lib/net.js index 8d88c69bba8c..35eb84d4988e 100644 --- a/lib/net.js +++ b/lib/net.js @@ -717,7 +717,13 @@ Socket.prototype.connect = function() { // TCP require('dns').lookup(arguments[1], function(err, ip, addressType) { if (err) { - self.emit('error', err); + // net.createConnection() creates a net.Socket object and + // immediately calls net.Socket.connect() on it (that's us). + // There are no event listeners registered yet so defer the + // error event to the next tick. + process.nextTick(function() { + self.emit('error', err); + }); } else { timers.active(self); self.type = addressType == 4 ? 'tcp4' : 'tcp6';