Skip to content

Commit dbbaf16

Browse files
committed
net: add CLI option for autoSelectFamilyAttemptTimeout
1 parent f098b7a commit dbbaf16

File tree

8 files changed

+44
-9
lines changed

8 files changed

+44
-9
lines changed

doc/api/cli.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,15 @@ added: v7.10.0
13291329

13301330
This option is a no-op. It is kept for compatibility.
13311331

1332+
### `--network-family-autoselection-attempt-timeout`
1333+
1334+
<!-- YAML
1335+
added: REPLACEME
1336+
-->
1337+
1338+
Sets the default value for the network family autoselection attempt timeout.
1339+
For more information, see [`net.getDefaultAutoSelectFamilyAttemptTimeout()`][].
1340+
13321341
### `--no-addons`
13331342

13341343
<!-- YAML
@@ -2635,6 +2644,7 @@ one is included in the list below.
26352644
* `--inspect`
26362645
* `--max-http-header-size`
26372646
* `--napi-modules`
2647+
* `--network-family-autoselection-attempt-timeout`
26382648
* `--no-addons`
26392649
* `--no-deprecation`
26402650
* `--no-experimental-fetch`
@@ -3161,6 +3171,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
31613171
[`dns.setDefaultResultOrder()`]: dns.md#dnssetdefaultresultorderorder
31623172
[`dnsPromises.lookup()`]: dns.md#dnspromiseslookuphostname-options
31633173
[`import` specifier]: esm.md#import-specifiers
3174+
[`net.getDefaultAutoSelectFamilyAttemptTimeout()`]: net.md#netgetdefaultautoselectfamilyattempttimeout
31643175
[`process.setUncaughtExceptionCaptureCallback()`]: process.md#processsetuncaughtexceptioncapturecallbackfn
31653176
[`process.setuid()`]: process.md#processsetuidid
31663177
[`setuid(2)`]: https://man7.org/linux/man-pages/man2/setuid.2.html

doc/api/net.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,8 @@ added:
17481748
-->
17491749

17501750
Gets the current default value of the `autoSelectFamilyAttemptTimeout` option of [`socket.connect(options)`][].
1751-
The initial default value is `250`.
1751+
The initial default value is `250` or the value specified via the command line
1752+
option `--network-family-autoselection-attempt-timeout`.
17521753

17531754
* Returns: {number} The current default value of the `autoSelectFamilyAttemptTimeout` option.
17541755

@@ -1763,7 +1764,8 @@ added:
17631764
Sets the default value of the `autoSelectFamilyAttemptTimeout` option of [`socket.connect(options)`][].
17641765

17651766
* `value` {number} The new default value, which must be a positive number. If the number is less than `10`,
1766-
the value `10` is used instead. The initial default value is `250`.
1767+
the value `10` is used instead. The initial default value is `250` or the value specified via the command line
1768+
option `--network-family-autoselection-attempt-timeout`.
17671769

17681770
## `net.isIP(input)`
17691771

lib/net.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ let dns;
134134
let BlockList;
135135
let SocketAddress;
136136
let autoSelectFamilyDefault = getOptionValue('--network-family-autoselection');
137-
let autoSelectFamilyAttemptTimeoutDefault = 250;
137+
let autoSelectFamilyAttemptTimeoutDefault = getOptionValue('--network-family-autoselection-attempt-timeout');
138138

139139
const { clearTimeout, setTimeout } = require('timers');
140140
const { kTimeout } = require('internal/timers');

src/node_options.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
383383
&EnvironmentOptions::network_family_autoselection,
384384
kAllowedInEnvvar,
385385
true);
386+
AddOption("--network-family-autoselection-attempt-timeout",
387+
"Sets the default value for the network family autoselection "
388+
"attempt timeout.",
389+
&EnvironmentOptions::network_family_autoselection_attempt_timeout,
390+
kAllowedInEnvvar);
386391
AddAlias("--enable-network-family-autoselection",
387392
"--network-family-autoselection");
388393
AddOption("--enable-source-maps",

src/node_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class EnvironmentOptions : public Options {
136136
int64_t heap_snapshot_near_heap_limit = 0;
137137
std::string heap_snapshot_signal;
138138
bool network_family_autoselection = true;
139+
uint64_t network_family_autoselection_attempt_timeout = 250;
139140
uint64_t max_http_header_size = 16 * 1024;
140141
bool deprecation = true;
141142
bool force_async_hooks_checks = true;

test/common/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,8 @@ const isPi = (() => {
146146
const isDumbTerminal = process.env.TERM === 'dumb';
147147

148148
// When using high concurrency or in the CI we need much more time for each connection attempt
149-
const defaultAutoSelectFamilyAttemptTimeout = platformTimeout(2500);
150-
// Since this is also used by tools outside of the test suite,
151-
// make sure setDefaultAutoSelectFamilyAttemptTimeout
152-
if (typeof net.setDefaultAutoSelectFamilyAttemptTimeout === 'function') {
153-
net.setDefaultAutoSelectFamilyAttemptTimeout(platformTimeout(defaultAutoSelectFamilyAttemptTimeout));
154-
}
149+
net.setDefaultAutoSelectFamilyAttemptTimeout(platformTimeout(net.getDefaultAutoSelectFamilyAttemptTimeout() * 10));
150+
const defaultAutoSelectFamilyAttemptTimeout = net.getDefaultAutoSelectFamilyAttemptTimeout();
155151

156152
const buildType = process.config.target_defaults ?
157153
process.config.target_defaults.default_configuration :
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
// Flags: --network-family-autoselection-attempt-timeout=123
4+
5+
require('../common');
6+
7+
const assert = require('assert');
8+
const { getDefaultAutoSelectFamilyAttemptTimeout } = require('net');
9+
10+
// Note that in test/common/index the default value is multiplied by 10.
11+
assert.strictEqual(getDefaultAutoSelectFamilyAttemptTimeout(), 1230);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const assert = require('assert');
6+
const { getDefaultAutoSelectFamilyAttemptTimeout } = require('net');
7+
8+
// Note that in test/common/index the default value is multiplied by 10.
9+
assert.strictEqual(getDefaultAutoSelectFamilyAttemptTimeout(), 2500);

0 commit comments

Comments
 (0)