Skip to content

Commit

Permalink
http: Change free sockets behavior to LIFO from FIFO.
Browse files Browse the repository at this point in the history
Sockets are added to the free list with .push() but they were
being removed with .shift().  This meant the sockets where being
removed in FIFO order, but this changes it to LIFO.  Since older
sockets may be closed based due to inactivity on the server it is
more likely that a socket that is recently used will be able to
successfully process the next request.
  • Loading branch information
rustyconover committed Jan 26, 2020
1 parent d6f1e39 commit 3d70376
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,

if (freeLen) {
// We have a free socket, so use that.
const socket = this.freeSockets[name].shift();
const socket = this.freeSockets[name].pop();
// Guard against an uninitialized or user supplied Socket.
const handle = socket._handle;
if (handle && typeof handle.asyncReset === 'function') {
Expand Down

0 comments on commit 3d70376

Please sign in to comment.