0

I build a server which get many requests and response to them.

In some cases, there is an error which cause the server to crush:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: ENOENT, open '/mnt/ace/0/file'

I have two problems:

  1. the stack trace doesn't give me any information about the line in my application that cause this exception (I can't do manually debugging because it happens just when I get 1000 request or more).
  2. I don't want that my server ould crush. I prefer that it will raise an exception, but will continue to work.

What the best implementation for this?

1

1 Answer 1

2

You can listen for that kind of stuff and not have it crash the app, but that's not always a great idea.

process.on('uncaughtException', function(err) {
  console.log('Something bad happened');
  console.log(err.stack);
});

In your case, have you tried checking ulimit settings? You may be having problems opening file handles under loads of 1000+.

Another way of thinking about this is to use domains (if you're using >= 0.8). Domains give you a finer grain of control over how you handle errors based on what contexts cause them.

var domain = require('domain').create();

domain.on('error', function(err) {
  console.log(err);
});

domain.run(function() {
  // Your code that might throw
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.