Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

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 #1202.
  • Loading branch information
bnoordhuis committed Aug 9, 2011
1 parent c318bd6 commit 60fd7e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/net_legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,13 @@ Socket.prototype.connect = function() {
// TCP
require('dns').lookup(host, 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
8 changes: 7 additions & 1 deletion lib/net_uv.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,13 @@ Socket.prototype.connect = function(port /* [host], [cb] */) {
debug("connect: find host " + host);
require('dns').lookup(host, 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);

Expand Down

0 comments on commit 60fd7e6

Please sign in to comment.