net: add CLI option for autoSelectFamilyAttemptTimeout

PR-URL: https://github.com/nodejs/node/pull/52474
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
This commit is contained in:
Paolo Insogna 2024-04-17 11:06:12 +02:00 committed by GitHub
parent 139624c788
commit 833e342f15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 42 additions and 9 deletions

View File

@ -1329,6 +1329,15 @@ added: v7.10.0
This option is a no-op. It is kept for compatibility.
### `--network-family-autoselection-attempt-timeout`
<!-- YAML
added: REPLACEME
-->
Sets the default value for the network family autoselection attempt timeout.
For more information, see [`net.getDefaultAutoSelectFamilyAttemptTimeout()`][].
### `--no-addons`
<!-- YAML
@ -2635,6 +2644,7 @@ one is included in the list below.
* `--inspect`
* `--max-http-header-size`
* `--napi-modules`
* `--network-family-autoselection-attempt-timeout`
* `--no-addons`
* `--no-deprecation`
* `--no-experimental-fetch`
@ -3161,6 +3171,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
[`dns.setDefaultResultOrder()`]: dns.md#dnssetdefaultresultorderorder
[`dnsPromises.lookup()`]: dns.md#dnspromiseslookuphostname-options
[`import` specifier]: esm.md#import-specifiers
[`net.getDefaultAutoSelectFamilyAttemptTimeout()`]: net.md#netgetdefaultautoselectfamilyattempttimeout
[`process.setUncaughtExceptionCaptureCallback()`]: process.md#processsetuncaughtexceptioncapturecallbackfn
[`process.setuid()`]: process.md#processsetuidid
[`setuid(2)`]: https://man7.org/linux/man-pages/man2/setuid.2.html

View File

@ -1748,7 +1748,8 @@ added:
-->
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.
@ -1763,7 +1764,8 @@ added:
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)`

View File

@ -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');

View File

@ -383,6 +383,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",

View File

@ -136,6 +136,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;

View File

@ -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 :

View File

@ -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));

View File

@ -0,0 +1,8 @@
'use strict';
const { platformTimeout } = require('../common');
const assert = require('assert');
const { getDefaultAutoSelectFamilyAttemptTimeout } = require('net');
assert.strictEqual(getDefaultAutoSelectFamilyAttemptTimeout(), platformTimeout(2500));