Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 982
Swizec Teller Avatar asked Nov 03 '10 14:11

Swizec Teller


People also ask

What is error Econnreset?

You might have guessed it already: it's a connection error. "ECONNRESET" means the other side of the TCP conversation abruptly closed its end of the connection. This is most probably due to one or more application protocol errors. You could look at the API server logs to see if it complains about something.


Video Answer


1 Answers

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);
});
like image 103
kanaka Avatar answered Oct 25 '22 19:10

kanaka