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: add maxTotalSockets to agent class #33617

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ added: REPLACEME
* {number}

By default set to `Infinity`. Determines how many concurrent sockets the agent
can have open.
can have open. Unlike `maxSockets`, this parameter across all origins.
rickyes marked this conversation as resolved.
Show resolved Hide resolved

### `agent.requests`
<!-- YAML
Expand Down
10 changes: 7 additions & 3 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const { once } = require('internal/util');
const { validateNumber } = require('internal/validators');

const kOnKeylog = Symbol('onkeylog');
const kRequestOptions = Symbol('requestOptions');
// New Agent code.

// The largest departure from the previous implementation is that
Expand Down Expand Up @@ -284,7 +285,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
}

// Used to create sockets for pending requests from different origin
req._options = options;
req[kRequestOptions] = options;

this.requests[name].push(req);
}
Expand Down Expand Up @@ -428,17 +429,20 @@ Agent.prototype.removeSocket = function removeSocket(s, options) {
debug('removeSocket, have a request, make a socket');
req = this.requests[name][0];
} else {
rickyes marked this conversation as resolved.
Show resolved Hide resolved
// TODO(rickyes): this logic will not be FIFO across origins. There might be
// older requests in a different origin, but if the origin which releases
// the socket has pending requests that will be prioritized.
for (const prop in this.requests) {
rickyes marked this conversation as resolved.
Show resolved Hide resolved
debug('removeSocket, have a request with different origin,' +
' make a socket');
req = this.requests[prop][0];
rickyes marked this conversation as resolved.
Show resolved Hide resolved
options = req._options;
options = req[kRequestOptions];
rickyes marked this conversation as resolved.
Show resolved Hide resolved
break;
}
}
rickyes marked this conversation as resolved.
Show resolved Hide resolved

if (req && options) {
delete req._options;
delete req[kRequestOptions];
rickyes marked this conversation as resolved.
Show resolved Hide resolved
// If we have pending requests and a socket gets closed make a new one
this.createSocket(req, options, (err, socket) => {
if (err)
Expand Down