Skip to content

Commit 4fabcfc

Browse files
evanlucasjasnell
authored andcommitted
Revert "net: remove unnecessary process.nextTick()"
This reverts commit 571882c. Removing the process.nextTick() call can prevent the consumer from being able to catch error events. PR-URL: #12854 Fixes: #12841 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent c7182b9 commit 4fabcfc

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/net.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,10 @@ function lookupAndConnect(self, options) {
10361036
// If host is an IP, skip performing a lookup
10371037
var addressType = cares.isIP(host);
10381038
if (addressType) {
1039-
internalConnect(self, host, port, addressType, localAddress, localPort);
1039+
nextTick(self[async_id_symbol], function() {
1040+
if (self.connecting)
1041+
internalConnect(self, host, port, addressType, localAddress, localPort);
1042+
});
10401043
return;
10411044
}
10421045

test/async-hooks/test-tcpwrap.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ const server = net
4848
{ port: server.address().port, host: server.address().address },
4949
common.mustCall(onconnected));
5050
const tcps = hooks.activitiesOfTypes('TCPWRAP');
51-
const tcpconnects = hooks.activitiesOfTypes('TCPCONNECTWRAP');
5251
assert.strictEqual(
5352
tcps.length, 2,
5453
'2 TCPWRAPs present when client is connecting');
55-
assert.strictEqual(
56-
tcpconnects.length, 1,
57-
'1 TCPCONNECTWRAP present when client is connecting');
54+
process.nextTick(() => {
55+
const tcpconnects = hooks.activitiesOfTypes('TCPCONNECTWRAP');
56+
assert.strictEqual(
57+
tcpconnects.length, 1,
58+
'1 TCPCONNECTWRAP present when client is connecting');
59+
});
60+
5861
tcp2 = tcps[1];
5962
assert.strictEqual(tcps.length, 2,
6063
'2 TCPWRAP present when client is connecting');

0 commit comments

Comments
 (0)