Skip to content

Commit

Permalink
net: add CLI option for autoSelectFamilyAttemptTimeout
Browse files Browse the repository at this point in the history
PR-URL: #52474
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
  • Loading branch information
ShogunPanda authored and marco-ippolito committed May 3, 2024
1 parent 6e85bc4 commit d116fa1
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 9 deletions.
11 changes: 11 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,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 @@ -2499,6 +2508,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`
Expand Down Expand Up @@ -2978,6 +2988,7 @@ done
[`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 @@ -1727,7 +1727,8 @@ added: v19.8.0
-->

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

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
5 changes: 5 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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,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));
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

const { platformTimeout } = require('../common');

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

assert.strictEqual(getDefaultAutoSelectFamilyAttemptTimeout(), platformTimeout(2500));

0 comments on commit d116fa1

Please sign in to comment.