Repository: nodejs/node
Pull request: net: increase network family autoselection timeout to 500ms

This is the same as https://github.com/nodejs/node/pull/56738, commit is attributed correctly to @hvanness, I just want this in (others do too obviously, [see](https://github.com/nodejs/node/issues/48145), [and](https://github.com/nodejs/node/issues/54359), [and](https://github.com/nodejs/node/pull/56738)) and that PR is stalled.

I'd also be happy with a slightly lower number if that's more comfortable, 400, or 350 perhaps. 250 is just too tight for people at the ends of the earth and no IPv6.

And .. IMO it's not a breaking change, to @ShogunPanda's original concerns, but opinions may vary.

/cc @mcollina @ShogunPanda @RafaelGSS 
---

The current 250ms timeout is too short for high-latency network environments, causing connection failures in IPv4-only networks when connecting to dual-stack hosts. This increases the timeout to 500ms to better handle satellite, cellular, and geographically distant connections.

The timeout should be reconsidered when parallel connections are implemented as per RFC 8305.

Refs: https://github.com/nodejs/node/issues/54359
Refs: https://github.com/nodejs/node/issues/48145


Changed files:
filename: doc/api/net.md
patch: @@ -1905,7 +1905,7 @@ added:
 -->
 
 Gets the current default value of the `autoSelectFamilyAttemptTimeout` option of [`socket.connect(options)`][].
-The initial default value is `250` or the value specified via the command line
+The initial default value is `500` or the value specified via the command line
 option `--network-family-autoselection-attempt-timeout`.
 
 * Returns: {number} The current default value of the `autoSelectFamilyAttemptTimeout` option.

filename: src/node_options.h
patch: @@ -155,7 +155,7 @@ class EnvironmentOptions : public Options {
   int64_t heap_snapshot_near_heap_limit = 0;
   std::string heap_snapshot_signal;
   bool network_family_autoselection = true;
-  uint64_t network_family_autoselection_attempt_timeout = 250;
+  uint64_t network_family_autoselection_attempt_timeout = 500;
   uint64_t max_http_header_size = 16 * 1024;
   bool deprecation = true;
   bool force_async_hooks_checks = true;

filename: test/common/index.js
patch: @@ -184,8 +184,9 @@ function isPi() {
   }
 }
 
-// When using high concurrency or in the CI we need much more time for each connection attempt
-net.setDefaultAutoSelectFamilyAttemptTimeout(platformTimeout(net.getDefaultAutoSelectFamilyAttemptTimeout() * 10));
+// When using high concurrency or in the CI we need much more time for each connection attempt.
+// Default 500ms becomes 2500ms for tests.
+net.setDefaultAutoSelectFamilyAttemptTimeout(platformTimeout(net.getDefaultAutoSelectFamilyAttemptTimeout() * 5));
 const defaultAutoSelectFamilyAttemptTimeout = net.getDefaultAutoSelectFamilyAttemptTimeout();
 
 const buildType = process.config.target_defaults ?

filename: test/parallel/test-net-autoselectfamily-attempt-timeout-cli-option.js
patch: @@ -7,4 +7,4 @@ const { platformTimeout } = require('../common');
 const assert = require('assert');
 const { getDefaultAutoSelectFamilyAttemptTimeout } = require('net');
 
-assert.strictEqual(getDefaultAutoSelectFamilyAttemptTimeout(), platformTimeout(123 * 10));
+assert.strictEqual(getDefaultAutoSelectFamilyAttemptTimeout(), platformTimeout(123 * 5));