Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Running the following server.js:

  cluster(app)
    .use(cluster.logger(path_to_logs))
    .use(cluster.stats())
    .use(cluster.pidfiles(path_to_pids))
    .use(cluster.cli())
    .use(cluster.repl(8888))
    .listen(3000);

Works as expected. However, let's throw in an unhandled exception.

   setTimeout(function () {
      throw new Error('User generated fault.');
   },5000);

The error executes after five seconds, and the effect is seemingly the same as ctrl+c if I had merely started the process with $ node server.js.

Now trying to restart the server using $ node server.js I receive the following error:

    Express server listening on port 3000

    node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
    Error: EADDRINUSE, Address already in use
    ...

And running $ ps aux | grep node I can see that I still have two node processes running. Killing them allows me to start the server again. But then the process repeats.

This is a problem because I wish to run forever, but doing so causes an infinite death cycle upon the first unhandled exception.


So my questions are:

  1. Do you have any further ideas on why this might occur?
  2. How can I listen for all exceptions and react by kill the process(es)
  3. Is the above a bad approach?




Now the funny part is that this behavior is only found running on my server, and not locally even though given the same server.js file. Consequently this must be a config-issue but I can still not seem to pin-point the issue.

Any help is appreciated.

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.