简体   繁体   中英

Node.js http.globalAgent.maxSockets not respected

Issue

When a request, having the response event registered, is aborted the maxSockets limit is no longer respected. It seems to happen only when the response contains some data.

Tested versions: v4.1.1 and v5.1.0

Client

var http = require('http');

http.globalAgent.maxSockets = 3;

for (var i = 0; i < 100; i++) {
    var request = http.get('http://127.0.0.1:8080', function () {
        // just register a listener...
    });
    request.setTimeout(1000, function () {
        console.log('T')
        this.abort();
    });
}

Server

require('http').createServer(function (reqest, response) {
    console.log('R');
    response.end('hello');
}).listen(8080);

Behavior

The server output is:

$ node server.js 
R
R
R
# 1s timeout here...
R
R
R
R
R
R
# 1s timeout here...
R
R
R
R
R
R
R
R
R
R
R
R
# 1s timeout here...
[...]

Is seems that every time, maxSockets is multiplied by 2 (3, 6, 12, 24, etc.), even though its value does not change. I was expecting groups of 3 instead.

Resuming the response, as opposed to aborting the request, works fine in this case.

好吧,这是Node.js的错误

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM