mirror of https://github.com/nodejs/node.git
Emit 'error' on tcp connection DNS error
parent
c0e18f37d4
commit
ae805f1057
56
lib/net.js
56
lib/net.js
|
@ -617,11 +617,15 @@ Stream.prototype.connect = function () {
|
||||||
// TODO dns resolution on arguments[1]
|
// TODO dns resolution on arguments[1]
|
||||||
var port = arguments[0];
|
var port = arguments[0];
|
||||||
self._resolving = true;
|
self._resolving = true;
|
||||||
lookupDomainName(arguments[1], function (ip, isV4) {
|
lookupDomainName(arguments[1], function (err, ip, isV4) {
|
||||||
self.type = isV4 ? 'tcp4' : 'tcp6';
|
if (err) {
|
||||||
self.fd = socket(self.type);
|
self.emit('error', err);
|
||||||
self._resolving = false;
|
} else {
|
||||||
doConnect(self, port, ip);
|
self.type = isV4 ? 'tcp4' : 'tcp6';
|
||||||
|
self.fd = socket(self.type);
|
||||||
|
self._resolving = false;
|
||||||
|
doConnect(self, port, ip);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
self.fd = socket('unix');
|
self.fd = socket('unix');
|
||||||
|
@ -761,7 +765,6 @@ exports.createServer = function (listener) {
|
||||||
// callback(dn, isV4
|
// callback(dn, isV4
|
||||||
function lookupDomainName (dn, callback) {
|
function lookupDomainName (dn, callback) {
|
||||||
var kind = isIP(dn);
|
var kind = isIP(dn);
|
||||||
debug('kind = ' + kind);
|
|
||||||
if (kind) {
|
if (kind) {
|
||||||
// Always wait until the next tick this is so people can do
|
// Always wait until the next tick this is so people can do
|
||||||
//
|
//
|
||||||
|
@ -769,23 +772,28 @@ function lookupDomainName (dn, callback) {
|
||||||
// server.addListener('listening', fn);
|
// server.addListener('listening', fn);
|
||||||
//
|
//
|
||||||
// Marginally slower, but a lot fewer WTFs.
|
// Marginally slower, but a lot fewer WTFs.
|
||||||
process.nextTick(function () { callback(dn, kind == 4 ? true : false); })
|
process.nextTick(function () {
|
||||||
|
callback(null, dn, kind == 4 ? true : false);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
debug("getaddrinfo 4 " + dn);
|
debug("getaddrinfo 4 " + dn);
|
||||||
getaddrinfo(dn, 4, function (r4) {
|
getaddrinfo(dn, 4, function (err, r4) {
|
||||||
if (r4 instanceof Error) throw r4;
|
if (err) {
|
||||||
if (r4.length > 0) {
|
callback(err);
|
||||||
|
} else if (r4.length > 0) {
|
||||||
debug("getaddrinfo 4 found " + r4);
|
debug("getaddrinfo 4 found " + r4);
|
||||||
callback(r4[0], true);
|
callback(null, r4[0], true);
|
||||||
} else {
|
} else {
|
||||||
debug("getaddrinfo 6 " + dn);
|
debug("getaddrinfo 6 " + dn);
|
||||||
getaddrinfo(dn, 6, function (r6) {
|
getaddrinfo(dn, 6, function (err, r6) {
|
||||||
if (r6 instanceof Error) throw r6;
|
if (err) {
|
||||||
if (r6.length < 0) {
|
callback(err);
|
||||||
throw new Error("No address associated with hostname " + dn);
|
} else if (r6.length == 0) {
|
||||||
|
callback(new Error("No address associated with hostname " + dn));
|
||||||
|
} else {
|
||||||
|
debug("getaddrinfo 6 found " + r6);
|
||||||
|
callback(null, r6[0], false);
|
||||||
}
|
}
|
||||||
debug("getaddrinfo 6 found " + r6);
|
|
||||||
callback(r6[0], false);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -847,11 +855,15 @@ Server.prototype.listen = function () {
|
||||||
} else {
|
} else {
|
||||||
// the first argument is the port, the second an IP
|
// the first argument is the port, the second an IP
|
||||||
var port = arguments[0];
|
var port = arguments[0];
|
||||||
lookupDomainName(arguments[1], function (ip, isV4) {
|
lookupDomainName(arguments[1], function (err, ip, isV4) {
|
||||||
self.type = isV4 ? 'tcp4' : 'tcp6';
|
if (err) {
|
||||||
self.fd = socket(self.type);
|
self.emit('error', err);
|
||||||
bind(self.fd, port, ip);
|
} else {
|
||||||
self._doListen();
|
self.type = isV4 ? 'tcp4' : 'tcp6';
|
||||||
|
self.fd = socket(self.type);
|
||||||
|
bind(self.fd, port, ip);
|
||||||
|
self._doListen();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1089,11 +1089,12 @@ static int AfterResolve(eio_req *req) {
|
||||||
struct resolve_request * rreq = (struct resolve_request *)(req->data);
|
struct resolve_request * rreq = (struct resolve_request *)(req->data);
|
||||||
|
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
Local<Value> argv[1];
|
Local<Value> argv[2];
|
||||||
|
|
||||||
if (req->result != 0) {
|
if (req->result != 0) {
|
||||||
|
argv[1] = Array::New();
|
||||||
if (req->result == EAI_NODATA) {
|
if (req->result == EAI_NODATA) {
|
||||||
argv[0] = Array::New();
|
argv[0] = Local<Value>::New(Null());
|
||||||
} else {
|
} else {
|
||||||
argv[0] = ErrnoException(req->result,
|
argv[0] = ErrnoException(req->result,
|
||||||
"getaddrinfo",
|
"getaddrinfo",
|
||||||
|
@ -1127,12 +1128,13 @@ static int AfterResolve(eio_req *req) {
|
||||||
address = address->ai_next;
|
address = address->ai_next;
|
||||||
}
|
}
|
||||||
|
|
||||||
argv[0] = results;
|
argv[0] = Local<Value>::New(Null());
|
||||||
|
argv[1] = results;
|
||||||
}
|
}
|
||||||
|
|
||||||
TryCatch try_catch;
|
TryCatch try_catch;
|
||||||
|
|
||||||
rreq->cb->Call(Context::GetCurrent()->Global(), 1, argv);
|
rreq->cb->Call(Context::GetCurrent()->Global(), 2, argv);
|
||||||
|
|
||||||
if (try_catch.HasCaught()) {
|
if (try_catch.HasCaught()) {
|
||||||
FatalException(try_catch);
|
FatalException(try_catch);
|
||||||
|
|
Loading…
Reference in New Issue