net: wrap connect in nextTick

Fixes an edge case regression introduced in
1bef717476.

With the lookup being skipped, an error could be emitted before an
error listener has been added.

An example of this was presented by changing the server’s IP address
and then immediately making a request to the old address.

Related: https://github.com/nodejs/io.js/pull/1823
PR-URL: https://github.com/nodejs/io.js/pull/2054
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
This commit is contained in:
Evan Lucas
2015-06-25 06:41:10 -05:00
parent 9180140231
commit af249fa8a1

View File

@@ -925,7 +925,9 @@ function lookupAndConnect(self, options) {
// TODO(evanlucas) should we hot path this for localhost?
var addressType = exports.isIP(host);
if (addressType) {
connect(self, host, port, addressType, localAddress, localPort);
process.nextTick(function() {
connect(self, host, port, addressType, localAddress, localPort);
});
return;
}