Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node + Express: unhandled ECONNRESET error

I have a Node + Express server running with forever on Digital Ocean. Every day or so the server throws an uncaught error and restarts. The server cycles on the same operation continuously but only throws the error randomly.

I have written error handlers in the code for all connections the server is making.

The node output:

events.js:72
    throw er; // Unhandled 'error' event
          ^
Error: read ECONNRESET
at errnoException (net.js:904:11)
at Pipe.onread (net.js:558:19)

I tried catching the error with:

app.use(function(err, req, res, next){
  console.error(err.stack);
});

But that didn't work. I am not using socket connections and there are no front-end clients connecting to this server.

like image 590
alyx Avatar asked Jan 25 '26 17:01

alyx


1 Answers

Based on other answers on Stackoverflow, I added these handlers:

app.listen(3137, 'localhost', function() {
    console.log("3137 ~ ~");
}).on('error', function(err){
    console.log('on error handler');
    console.log(err);
});


process.on('uncaughtException', function(err) {
    console.log('process.on handler');
    console.log(err);
});

Hopefully either one catches the error...

like image 168
alyx Avatar answered Jan 28 '26 08:01

alyx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!