diff --git a/doc/api/cli.md b/doc/api/cli.md index e8586b7c1c2aff..acb25165c4f756 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -1284,6 +1284,15 @@ added: v7.10.0 This option is a no-op. It is kept for compatibility. +### `--network-family-autoselection-attempt-timeout` + + + +Sets the default value for the network family autoselection attempt timeout. +For more information, see [`net.getDefaultAutoSelectFamilyAttemptTimeout()`][]. + ### `--no-addons` Gets the current default value of the `autoSelectFamilyAttemptTimeout` option of [`socket.connect(options)`][]. -The initial default value is `250`. +The initial default value is `250` or the value specified via the command line +option `--network-family-autoselection-attempt-timeout`. * Returns: {number} The current default value of the `autoSelectFamilyAttemptTimeout` option. @@ -1740,7 +1741,8 @@ added: v19.8.0 Sets the default value of the `autoSelectFamilyAttemptTimeout` option of [`socket.connect(options)`][]. * `value` {number} The new default value, which must be a positive number. If the number is less than `10`, - the value `10` is used instead. The initial default value is `250`. + the value `10` is used instead. The initial default value is `250` or the value specified via the command line + option `--network-family-autoselection-attempt-timeout`. ## `net.isIP(input)` diff --git a/lib/net.js b/lib/net.js index 82205e4352983c..4efe7eff6dab69 100644 --- a/lib/net.js +++ b/lib/net.js @@ -134,7 +134,7 @@ let dns; let BlockList; let SocketAddress; let autoSelectFamilyDefault = getOptionValue('--network-family-autoselection'); -let autoSelectFamilyAttemptTimeoutDefault = 250; +let autoSelectFamilyAttemptTimeoutDefault = getOptionValue('--network-family-autoselection-attempt-timeout'); const { clearTimeout, setTimeout } = require('timers'); const { kTimeout } = require('internal/timers'); diff --git a/src/node_options.cc b/src/node_options.cc index e5dc0c517e0907..8d046d8922f102 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -369,6 +369,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { &EnvironmentOptions::network_family_autoselection, kAllowedInEnvvar, true); + AddOption("--network-family-autoselection-attempt-timeout", + "Sets the default value for the network family autoselection " + "attempt timeout.", + &EnvironmentOptions::network_family_autoselection_attempt_timeout, + kAllowedInEnvvar); AddAlias("--enable-network-family-autoselection", "--network-family-autoselection"); AddOption("--enable-source-maps", diff --git a/src/node_options.h b/src/node_options.h index a62d0ae32c44d1..703e1d2b1bfc55 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -133,6 +133,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 max_http_header_size = 16 * 1024; bool deprecation = true; bool force_async_hooks_checks = true; diff --git a/test/common/index.js b/test/common/index.js index 4aeac8293b30fa..c108ecf252c365 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -146,12 +146,8 @@ const isPi = (() => { const isDumbTerminal = process.env.TERM === 'dumb'; // When using high concurrency or in the CI we need much more time for each connection attempt -const defaultAutoSelectFamilyAttemptTimeout = platformTimeout(2500); -// Since this is also used by tools outside of the test suite, -// make sure setDefaultAutoSelectFamilyAttemptTimeout -if (typeof net.setDefaultAutoSelectFamilyAttemptTimeout === 'function') { - net.setDefaultAutoSelectFamilyAttemptTimeout(platformTimeout(defaultAutoSelectFamilyAttemptTimeout)); -} +net.setDefaultAutoSelectFamilyAttemptTimeout(platformTimeout(net.getDefaultAutoSelectFamilyAttemptTimeout() * 10)); +const defaultAutoSelectFamilyAttemptTimeout = net.getDefaultAutoSelectFamilyAttemptTimeout(); const buildType = process.config.target_defaults ? process.config.target_defaults.default_configuration : diff --git a/test/parallel/test-net-autoselectfamily-attempt-timeout-cli-option.js b/test/parallel/test-net-autoselectfamily-attempt-timeout-cli-option.js new file mode 100644 index 00000000000000..474ffe024cd549 --- /dev/null +++ b/test/parallel/test-net-autoselectfamily-attempt-timeout-cli-option.js @@ -0,0 +1,10 @@ +'use strict'; + +// Flags: --network-family-autoselection-attempt-timeout=123 + +const { platformTimeout } = require('../common'); + +const assert = require('assert'); +const { getDefaultAutoSelectFamilyAttemptTimeout } = require('net'); + +assert.strictEqual(getDefaultAutoSelectFamilyAttemptTimeout(), platformTimeout(123 * 10)); diff --git a/test/parallel/test-net-autoselectfamily-attempt-timeout-default-value.js b/test/parallel/test-net-autoselectfamily-attempt-timeout-default-value.js new file mode 100644 index 00000000000000..782276952708a0 --- /dev/null +++ b/test/parallel/test-net-autoselectfamily-attempt-timeout-default-value.js @@ -0,0 +1,8 @@ +'use strict'; + +const { platformTimeout } = require('../common'); + +const assert = require('assert'); +const { getDefaultAutoSelectFamilyAttemptTimeout } = require('net'); + +assert.strictEqual(getDefaultAutoSelectFamilyAttemptTimeout(), platformTimeout(2500));