Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit 4e204f37fd994b3bd11a829c9f6938b5a3ca9774 1 parent e00c2ec
@bnoordhuis bnoordhuis authored
Showing with 7 additions and 1 deletion.
  1. +7 −1 lib/net.js
View
8 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';
Please sign in to comment.
Something went wrong with that request. Please try again.