Skip to content

Commit

Permalink
http: Change agent free socket behavior
Browse files Browse the repository at this point in the history
Rather than destroying the last used socket destroy
the oldest socket in the free list in push() on the
last recently used socket.
  • Loading branch information
rustyconover committed Jan 27, 2020
1 parent 3d70376 commit 9cd73fb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,15 @@ function Agent(options) {
if (this.sockets[name])
count += this.sockets[name].length;

if (count > this.maxSockets || freeLen >= this.maxFreeSockets) {
if (count > this.maxSockets) {
socket.destroy();
} else if (this.keepSocketAlive(socket)) {
freeSockets = freeSockets || [];
this.freeSockets[name] = freeSockets;
if (freeLen >= this.maxFreeSockets) {
this.freeSockets[name].shift().destroy();
} else {
freeSockets = freeSockets || [];
this.freeSockets[name] = freeSockets;
}
socket[async_id_symbol] = -1;
socket._httpMessage = null;
this.removeSocket(socket, options);
Expand Down

0 comments on commit 9cd73fb

Please sign in to comment.