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.
This commit is contained in:
Ben Noordhuis 2011-08-09 16:26:42 +02:00
Родитель 5b58473b40
Коммит fa378ee4d8
2 изменённых файлов: 14 добавлений и 2 удалений

Просмотреть файл

@ -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 {
addressType = addressType || 4;

Просмотреть файл

@ -469,7 +469,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);