【问题标题】:{ [Error: socket hang up] code: 'ECONNRESET' }{ [错误:套接字挂起]代码:'ECONNRESET'}
【发布时间】:2015-08-27 08:33:39
【问题描述】:

所以我在async.each 中使用request,在调用了几个请求后它给了我{[错误:套接字挂断]代码:'ECONNRESET'}。知道我做错了什么吗?

async.eachSeries(videos, function (video, next) {
    if (initialVideosObj[video.id] == false) {
        var url = config.youtubeApiUrl + "videos?part=contentDetails,snippet,player&key=" + config.youtubeKey + "&regionCode=" + config.regionCode + "&id=" + video.id
        request(url, function (error, response, body) {
            if (error) {
                console.error("ERROR:", error, url);// afet a few requests it gives me { [Error: socket hang up] code: 'ECONNRESET' }, but the funny thing is that the logged url has no problem when I call it manually!
                next(error);
            } else if (response.statusCode == 200) {
                var parsedVideoData = JSON.parse(body);
                video["duration"] = convertDuration(parsedVideoData.items[0].contentDetails.duration);
                video["yt_subscribe_id"] = parsedVideoData.items[0].snippet.channelId;                                                        
                next();
            }
        });
    } else {
        setImmediate(next);//Since there is no async operation I use setImmediate!
    }
}, function (err) {
    if (err) {
        console.error(err.stack, err);
    } else {                                                
        console.log("Done")
    }
});

更新:

这是我得到的错误堆栈:

{ [Error: socket hang up] code: 'ECONNRESET' }
/myProj/node_modules/longjohn/dist/longjohn.js:185
        throw e;
              ^
/myProj/getVideo.js:207:71,done (/myProj/node_modules/async/lib/async.js:126:15),/myProj/node_modules/async/lib/async.js:32:16,/myProj/getVideo.js:141:45,Request._callback (/myProj/getVideo.js:399:13),self.callback (/myProj/node_modules/request/request.js:354:22),Request.emit (events.js:107:17),Request.onRequestError (/myProj/node_modules/request/request.js:1011:8)

【问题讨论】:

  • 您能否使用github.com/mattinsler/longjohn 获取包含异步操作的长堆栈跟踪并显示堆栈跟踪。
  • 它是如何工作的?我应该只安装并需要它吗?就这样?文档没有任何示例!
  • 嘿@KietThanhVo 我现在添加了错误堆栈;

标签: javascript node.js asynchronous google-api request


【解决方案1】:

这些请求的发送速度有多快?也许你正在达到他们的速率限制?有关详细信息,请参阅https://developers.google.com/youtube/v3/getting-started#quota。这可以解释为什么手动操作永远不会给您带来错误。

【讨论】:

    猜你喜欢
    • 2013-09-12
    • 2015-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-20
    • 2015-09-13
    • 2014-10-02
    • 1970-01-01
    相关资源
    最近更新 更多