Skip to content
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.

### `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 {
// 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) {
debug('removeSocket, have a request with different origin,' +
' make a socket');
req = this.requests[prop][0];
options = req._options;
options = req[kRequestOptions];
break;
}
}

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