Nodejs server hanging from time to time

node.jsunix

I have a node server (0.6.6) running an Express application, along with Mongoose and s3, on an Ubuntu 11.04 machine.

Several times per hour, the server is hanging. That means that the application is working fine, I see the express loggings, and then all of a sudden the server stops responding. No errors, no traces, no loggings, and strangely enough the browser won't show the request even in the network debugging window. From any machine in the local network it's the same behaviour. I restart the server and it's okay again for several minutes, then again starts to hang, everytime while doing something different.

The same application on Amazon on the same Ubuntu version works fine and never hangs.

I know all this is kind of vague, but I don't know where to start. Has any of you seen something like this before? Any idea?

Best Answer

So, there's two causes that I've found out could both even for themselves cause the described behaviour.

  1. Piping to a log process. In my upstart script I've had a line saying something like exec su nodejs node /home/nodejs/server.js | /home/nodejs/logger.js this would make the upstart daemon supervise the logging process instead of the server. Thus, a crashing server would go unnoticed and appear to be stalled. (instead, one could use <<< to pipe from right to left)

  2. process.on('uncaughtException', ...) can make the a node app hang. I think one of the modules I've been using had a debug mode that enabled that event.

Related Topic