簡體   English   中英

不尊重Node.js http.globalAgent.maxSockets

[英]Node.js http.globalAgent.maxSockets not respected

問題

當注冊了response事件的請求中止時,將不再遵守maxSockets限制。 它似乎僅在響應包含一些數據時發生。

經過測試的版本: v4.1.1和v5.1.0

客戶

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();
    });
}

服務器

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

行為

服務器輸出為:

$ 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...
[...]

似乎每次將maxSockets乘以2( maxSockets等),即使其值沒有變化。 我原本希望是3人一組。

在這種情況下, 恢復響應(而不是中止請求)可以正常工作。

好吧,這是Node.js的錯誤

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM