Skip to content

Commit

Permalink
net: add CLI option for autoSelectFamilyAttemptTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
ShogunPanda committed Apr 11, 2024
1 parent 21211a3 commit ec1a58c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 9 deletions.
10 changes: 10 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -3161,6 +3170,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
Expand Down
6 changes: 4 additions & 2 deletions doc/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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)`

Expand Down
2 changes: 1 addition & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 4 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ 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",
Expand Down
1 change: 1 addition & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

// Flags: --network-family-autoselection-attempt-timeout=123

require('../common');

const assert = require('assert');
const { getDefaultAutoSelectFamilyAttemptTimeout } = require('net');

// Note that in test/common/index the default value is multiplied by 10.
assert.strictEqual(getDefaultAutoSelectFamilyAttemptTimeout(), 1230);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

require('../common');

const assert = require('assert');
const { getDefaultAutoSelectFamilyAttemptTimeout } = require('net');

// Note that in test/common/index the default value is multiplied by 10.
assert.strictEqual(getDefaultAutoSelectFamilyAttemptTimeout(), 2500);

0 comments on commit ec1a58c

Please sign in to comment.