Skip to content

Commit

Permalink
Refactor socket add logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rustyconover committed Jan 27, 2020
1 parent 9cd73fb commit 4ef4a2d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ function Agent(options) {
if (this.sockets[name])
count += this.sockets[name].length;

if (count > this.maxSockets) {
socket.destroy();
} else if (this.keepSocketAlive(socket)) {
if (this.keepSocketAlive(socket) &&
this.maxFreeSockets > 0 &&
count <= this.maxSockets) {
if (freeLen >= this.maxFreeSockets) {
this.freeSockets[name].shift().destroy();
const oldest = this.freeSockets[name].shift();
oldest.destroy();
} else {
freeSockets = freeSockets || [];
this.freeSockets[name] = freeSockets;
Expand Down

0 comments on commit 4ef4a2d

Please sign in to comment.