Skip to content

Commit

Permalink
net: defer DNS lookup error events to next tick
Browse files Browse the repository at this point in the history
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 nodejs#1202.
  • Loading branch information
bnoordhuis committed Aug 12, 2011
1 parent e00c2ec commit 4e204f3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 4e204f3

Please sign in to comment.