summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/_http_agent.js2
-rw-r--r--test/parallel/test-http-agent-maxsockets-regress-4050.js43
2 files changed, 43 insertions, 2 deletions
diff --git a/lib/_http_agent.js b/lib/_http_agent.js
index 305baa2cbd..c6e3ef63bd 100644
--- a/lib/_http_agent.js
+++ b/lib/_http_agent.js
@@ -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 || [];
@@ -78,7 +77,6 @@ function Agent(options) {
freeSockets.push(socket);
}
} else {
- self.removeSocket(socket, options);
socket.destroy();
}
}
diff --git a/test/parallel/test-http-agent-maxsockets-regress-4050.js b/test/parallel/test-http-agent-maxsockets-regress-4050.js
new file mode 100644
index 0000000000..1cbe37cf0c
--- /dev/null
+++ b/test/parallel/test-http-agent-maxsockets-regress-4050.js
@@ -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();
+ }
+ });
+ }
+});