Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP agent: remove excess calls to removeSocket #4172

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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: 0 additions & 2 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ function Agent(options) {
count += self.sockets[name].length;

if (count > self.maxSockets || freeLen >= self.maxFreeSockets) {
self.removeSocket(socket, options);
socket.destroy();
} else {
freeSockets = freeSockets || [];
Expand All @@ -78,7 +77,6 @@ function Agent(options) {
freeSockets.push(socket);
}
} else {
self.removeSocket(socket, options);
socket.destroy();
}
}
Expand Down
43 changes: 43 additions & 0 deletions test/parallel/test-http-agent-maxsockets-regress-4050.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');

const MAX_SOCKETS = 2;

const agent = new http.Agent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: MAX_SOCKETS,
maxFreeSockets: 2
});

const server = http.createServer(function(req, res) {
res.end('hello world');
});

function get(path, callback) {
return http.get({
host: 'localhost',
port: common.PORT,
agent: agent,
path: path
}, callback);
}

server.listen(common.PORT, function() {
var finished = 0;
const num_requests = 6;
for (var i = 0; i < num_requests; i++) {
const request = get('/1', function() {
});
request.on('response', function() {
request.abort();
const sockets = agent.sockets[Object.keys(agent.sockets)[0]];
assert(sockets.length <= MAX_SOCKETS);
if (++finished === num_requests) {
server.close();
}
});
}
});