Skip to content

Commit

Permalink
net: fix setting of value in 'setDefaultAutoSelectFamilyAttemptTimeout'
Browse files Browse the repository at this point in the history
Document describes that the value have to be 10 if passed value to
`setDefaultAutoSelectFamilyAttemptTimeout` is less than 10.
So need to use 10 for 'if' statement and fix typo in document.

Refs: https://github.com/nodejs/node/blob/main/doc/api/net.md#netsetdefaultautoselectfamilyattempttimeoutvalue
PR-URL: #47012
Reviewed-By: Paolo Insogna <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
  • Loading branch information
deokjinkim authored and targos committed Mar 14, 2023
1 parent e754277 commit 40a7b0b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ added: REPLACEME
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 insted The initial default value is `250`.
the value `10` is used instead. The initial default value is `250`.

## `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 @@ -247,7 +247,7 @@ function getDefaultAutoSelectFamilyAttemptTimeout() {
function setDefaultAutoSelectFamilyAttemptTimeout(value) {
validateInt32(value, 'value', 1);

if (value < 1) {
if (value < 10) {
value = 10;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ for (const autoSelectFamilyAttemptTimeout of [-10, 0]) {
net.setDefaultAutoSelectFamilyAttemptTimeout(autoSelectFamilyAttemptTimeout);
}, { code: 'ERR_OUT_OF_RANGE' });
}

// Check the default value of autoSelectFamilyAttemptTimeout is 10
// if passed number is less than 10
for (const autoSelectFamilyAttemptTimeout of [1, 9]) {
net.setDefaultAutoSelectFamilyAttemptTimeout(autoSelectFamilyAttemptTimeout);
assert.strictEqual(net.getDefaultAutoSelectFamilyAttemptTimeout(), 10);
}

0 comments on commit 40a7b0b

Please sign in to comment.