Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,10 @@ function lookupAndConnect(self, options) {
// If host is an IP, skip performing a lookup
var addressType = cares.isIP(host);
if (addressType) {
internalConnect(self, host, port, addressType, localAddress, localPort);
nextTick(self[async_id_symbol], function() {
if (self.connecting)
internalConnect(self, host, port, addressType, localAddress, localPort);
});
return;
}

Expand Down
11 changes: 7 additions & 4 deletions test/async-hooks/test-tcpwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ const server = net
{ port: server.address().port, host: server.address().address },
common.mustCall(onconnected));
const tcps = hooks.activitiesOfTypes('TCPWRAP');
const tcpconnects = hooks.activitiesOfTypes('TCPCONNECTWRAP');
assert.strictEqual(
tcps.length, 2,
'2 TCPWRAPs present when client is connecting');
assert.strictEqual(
tcpconnects.length, 1,
'1 TCPCONNECTWRAP present when client is connecting');
process.nextTick(() => {
const tcpconnects = hooks.activitiesOfTypes('TCPCONNECTWRAP');
assert.strictEqual(
tcpconnects.length, 1,
'1 TCPCONNECTWRAP present when client is connecting');
});

tcp2 = tcps[1];
assert.strictEqual(tcps.length, 2,
'2 TCPWRAP present when client is connecting');
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-http-client-immediate-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

// Make sure http.request() can catch immediate errors in
// net.createConnection().

const common = require('../common');
const assert = require('assert');
const http = require('http');
const req = http.get({ host: '127.0.0.1', port: 1 });
req.on('error', common.mustCall((err) => {
assert.strictEqual(err.code, 'ECONNREFUSED');
}));