请求在计数为5时开始超时



我正在循环浏览一个长URL列表,以便"取消排序"它们-
我正在使用一个模块来完成此操作。

我的代码低于

var async = require('async'),
    unshorten = require('unshorten');
var urls = [
    //all these are google
    'http://t.co/twxHxOtTvy',
    'http://t.co/twxHxOtTvy',
    'http://t.co/twxHxOtTvy',
    'http://t.co/twxHxOtTvy',
    'http://t.co/twxHxOtTvy',
    'http://t.co/twxHxOtTvy',
    'http://t.co/twxHxOtTvy',
    'http://t.co/twxHxOtTvy',
    'http://t.co/twxHxOtTvy',
    'http://t.co/twxHxOtTvy'
]
async.eachSeries(urls, function(shortUrl, callback) {
    unshorten(shortUrl, function(longUrl) {
        console.log(longUrl + ' is where it’s at!');
        callback();
    });
});

我的问题是,它达到5,然后开始计时。。。

如果我停止节点应用程序并重新启动它,它将再次达到5,然后超时。

我怀疑我达到了某种最大连接限制,但我不知道在哪里?

为了简单起见,unshorten的来源如下:

(function() {
    var urlLibrary = require('url'),
        http = require('http'),
        https = require('https');
    function unshorten(url, callback) {
        url = urlLibrary.parse(url);
        ('https' == url.protocol ? https : http).request(
            {
                'method': 'HEAD',
                'host': url.host,
                'path': url.pathname
            },
            function(response) {
                if (~[301, 302].indexOf(response.statusCode)) {
                    (callback || console.log)(response.headers.location);
                    return;
                }
            }
        ).end();
    }
    module.exports = unshorten;
}());

您几乎可以肯定地达到了node.js默认的http代理最大套接字限制5。阅读hyperquest自述中的greant rant@substack,了解更多详细信息。还可以考虑其他库,如superagent(我个人最喜欢的)、hyperquery、request等。