Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: refactor to use min of validateNumber for maxTotalSockets #46115

Merged
merged 1 commit into from Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 1 addition & 10 deletions lib/_http_agent.js
Expand Up @@ -30,7 +30,6 @@ const {
ArrayPrototypeSome,
ArrayPrototypeSplice,
FunctionPrototypeCall,
NumberIsNaN,
NumberParseInt,
ObjectCreate,
ObjectKeys,
Expand All @@ -51,11 +50,6 @@ let debug = require('internal/util/debuglog').debuglog('http', (fn) => {
});
const { AsyncResource } = require('async_hooks');
const { async_id_symbol } = require('internal/async_hooks').symbols;
const {
codes: {
ERR_OUT_OF_RANGE,
},
} = require('internal/errors');
const {
kEmptyObject,
once,
Expand Down Expand Up @@ -125,10 +119,7 @@ function Agent(options) {
validateOneOf(this.scheduling, 'scheduling', ['fifo', 'lifo']);

if (this.maxTotalSockets !== undefined) {
validateNumber(this.maxTotalSockets, 'maxTotalSockets');
if (this.maxTotalSockets <= 0 || NumberIsNaN(this.maxTotalSockets))
throw new ERR_OUT_OF_RANGE('maxTotalSockets', '> 0',
this.maxTotalSockets);
validateNumber(this.maxTotalSockets, 'maxTotalSockets', 1);
} else {
this.maxTotalSockets = Infinity;
}
Expand Down
2 changes: 0 additions & 2 deletions test/parallel/test-http-agent-maxtotalsockets.js
Expand Up @@ -20,8 +20,6 @@ assert.throws(() => new http.Agent({
}), {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "maxTotalSockets" is out of range. ' +
`It must be > 0. Received ${item}`,
});
});

Expand Down