Description
Version
v20.11.1
Platform
Linux testserver 3.10.0-1160.114.2.el7.x86_64 #1 SMP Sun Mar 3 08:18:39 EST 2024 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
Net
What steps will reproduce the bug?
`
const { Socket } = require('net');
const sock = new Socket();
sock.connect({
host: 'latencyontheothersideoftheplanet.com',
port: 4222,
});
sock.on('connect', () => {
console.log('Connected to server');
// Send data to the server
sock.write('Hello, server!');
});
sock.on('data', (data) => {
console.log(Received data from server: ${data}
);
// Close the socket
sock.end();
});
sock.on('end', () => {
console.log('Disconnected from server');
});
`
I try to connect from a japan server to a european server.
Node 20.0.0, the default value of autoSelectFamily in socket.connect() changed from false to true.
in this case the latency is too high and "let autoSelectFamilyAttemptTimeoutDefault = 250;" define into Net.js is too low, so the query fail every time with a timeout for ipv4 (rais the timeout on algorithm) and with ENETUNREACH for ipv6 (this is normal as I dont have ipv6 network).
For fixing the issue (workaround) I set :
`
export NODE_OPTIONS=--no-network-family-autoselection
`
This parameter disable "happy eyeballs" algorithm add into ndoejs 20.
I know the timeout can be enlarge by "setDefaultAutoSelectFamilyAttemptTimeout" but this require an update of code.
I think its should be great to define this parameter as env variable for limiting breaking change not documented for this.
One more point, I think if there are no ipv6 network available no need to apply timeout.
How often does it reproduce? Is there a required condition?
you need to have a server with high latency connection greater than 250 ms
What is the expected behavior? Why is that the expected behavior?
I want my code works as on nodejs18 without timeout on connect with a server which has bad connection
What do you see instead?
I see a timeout on ivp4,
Additional information
No response