[Solved] How to handle ECONNRESET, Connection reset by peer
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
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.
Solution #1:
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);
});
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .