Skip to content

Commit 4ef4a2d

Browse files
committed
Refactor socket add logic
1 parent 9cd73fb commit 4ef4a2d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/_http_agent.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,12 @@ function Agent(options) {
112112
if (this.sockets[name])
113113
count += this.sockets[name].length;
114114

115-
if (count > this.maxSockets) {
116-
socket.destroy();
117-
} else if (this.keepSocketAlive(socket)) {
115+
if (this.keepSocketAlive(socket) &&
116+
this.maxFreeSockets > 0 &&
117+
count <= this.maxSockets) {
118118
if (freeLen >= this.maxFreeSockets) {
119-
this.freeSockets[name].shift().destroy();
119+
const oldest = this.freeSockets[name].shift();
120+
oldest.destroy();
120121
} else {
121122
freeSockets = freeSockets || [];
122123
this.freeSockets[name] = freeSockets;

0 commit comments

Comments
 (0)