diff --git a/lib/net.js b/lib/net.js index a3d778a4488..67e191fa213 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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; } diff --git a/test/async-hooks/test-tcpwrap.js b/test/async-hooks/test-tcpwrap.js index cbad3f3ddf3..08277792292 100644 --- a/test/async-hooks/test-tcpwrap.js +++ b/test/async-hooks/test-tcpwrap.js @@ -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');