簡體   English   中英

多個http.get請求的套接字掛斷錯誤

[英]Socket hang up error with multiple http.get requests

我正在使用node.js使用http.get請求和async.eachLimit方法下載大量文件。

當我將異步方法的並發性增加到5以上時,這個“套接字掛起”錯誤很容易出現,我無法理解為什么。

任何人都可以闡明為什么會這樣嗎?

這是收到的錯誤

events.js:72
        throw er; // Unhandled 'error' event
          ^
Error: socket hang up
    at createHangUpError (http.js:1472:15)
    at Socket.socketOnEnd [as onend] (http.js:1568:23)
    at Socket.g (events.js:180:16)
    at Socket.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

這是使用async.eachLimit方法重復調用的函數

        var urlPre = "http://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/?key=";
        var urlSidPre = "&steamid=";
        var urlInvSuf = "&inventory=yes";
        var URL = urlPre+steam_API+urlSidPre+sid+urlInvSuf;
        //log.info("Downloading "+ alias + "'s inventory");
        http.get(URL, function (res) {
            var body = '';
            res.on('data', function (data) {
                body+=data; 
                fs.appendFile(invLoc, data);
            });
            res.on('end', function() {
                try {
                    inventory = JSON.parse(body);
                    //log.info(alias + "'s inventory downloaded");
                } catch (e) {
                    fs.unlinkSync(invLoc);
                    log.error("parsing " + alias+"'s inventory");
                    loadInventory(sid, alias, invFolder, callback); 
                    return;
                }
                callback(inventory, alias);
            });
            res.on('error', function (e, socket) {
                log.error(alias + " inventory error")
            })
        })

我認為你的問題與這些人的問題是一樣的:

https://github.com/ether/etherpad-lite/issues/1541

嘗試向套接字的error event添加偵聽器

http.get(...)
.on('error', function(e) {
  console.log("Got error: " + e.message);
});

暫無
暫無

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

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