简体   繁体   English

不尊重Node.js http.globalAgent.maxSockets

[英]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. 当注册了response事件的请求中止时,将不再遵守maxSockets限制。 It seems to happen only when the response contains some data. 它似乎仅在响应包含一些数据时发生。

Tested versions: v4.1.1 and v5.1.0 经过测试的版本: v4.1.1和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. 似乎每次将maxSockets乘以2( maxSockets等),即使其值没有变化。 I was expecting groups of 3 instead. 我原本希望是3人一组。

Resuming the response, as opposed to aborting the request, works fine in this case. 在这种情况下, 恢复响应(而不是中止请求)可以正常工作。

好吧,这是Node.js的错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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