7

In my node.js app which uses the cluster module, I'm intermittently seeing errors like this:

events.js:71
        throw er; // Unhandled 'error' event
              ^
Error: read ECONNRESET
    at errnoException (net.js:863:11)
    at TCP.onread (net.js:524:19)

This brings down my whole app, and so far the only way I've been able to deal with these is by binding a process.on('uncaughtException'). I'd like to figure out the underlying cause, but the above stack trace is pretty useless.

Is there some way to figure out what's causing these exceptions?

I should note that I'm seeing these only in the cluster master, not the workers, which leads me to suspect that they have something to do with the way the cluster modules does its magic in distributing connections to workers.

Steve Bennett
  • 114,604
  • 39
  • 168
  • 219
Matt Zukowski
  • 4,469
  • 4
  • 37
  • 38
  • possible duplicate of [How to debug a socket hang up error in NodeJS?](http://stackoverflow.com/questions/10814481/how-to-debug-a-socket-hang-up-error-in-nodejs) – e-sushi Jul 14 '13 at 08:53

2 Answers2

1

This answer was helpful: https://stackoverflow.com/a/11542134/233370

Basically, I installed longjohn and was then able to get the full async stack trace to figure out the underlying cause (rabbit.js in my case).

Community
  • 1
  • 1
Matt Zukowski
  • 4,469
  • 4
  • 37
  • 38
0

It seems that express enabled keep-alive by default. In order to close connection after response you can add res.set("Connection", "close");

Alternatively you can add a middleware in your app to close connection after each response:

 app.use(function(req, res, next) {
         res.set("Connection", "close");
         next();
     });
alexopoulos7
  • 794
  • 7
  • 27