如何处理ECONNRESET,对等连接重置 [英] How to handle ECONNRESET, Connection reset by peer

查看:83
本文介绍了如何处理ECONNRESET,对等连接重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的许多node.js进程由于ECONNRESET错误而崩溃.这是我可以看到的输出:

A lot of my node.js processes are crashing with the ECONNRESET error. Here's the output I can see:

node.js:50
    throw e;
    ^
Error: ECONNRESET, Connection reset by peer
    at Client._readImpl (net:320:14)
    at IOWatcher.callback (net:470:24)
    at node.js:607:9

有人知道如何处理吗?这不是一个非常有用的堆栈跟踪,所以我不知道它在哪里发生.我是否应该使用try/catch块包装通过http访问远程源的所有访问权限?还是有更好的方法?

Does anyone know how to handle this? It's not a very useful stack trace so I have no idea where it's happening. Should I just wrap any and all access to a remote source via http with a try/catch block? Or is there a better way?

通常,我不关心是否会发生这种情况,或者是否因此而无法完成某些任务.我关心的是,该过程应该将其忽略,然后继续执行下一个任务.

In general I don't care if this does happen or if some task does not get completed because of this. What I do care about is that the process should just shrug it off and work on the next task.

推荐答案

您需要为套接字附加错误事件.如果不这样做,那么默认操作是在发生错误时引发异常.

You need to attach to the error Event for your socket. If you don't, then the default action is to throw an exception when an error occurs.

socket.on('error', function (exc) {
    sys.log("ignoring exception: " + exc);
});

这篇关于如何处理ECONNRESET,对等连接重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆