Or Smith
Or Smith

Reputation: 3616

Debugging in node.js

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?

Upvotes: 0

Views: 52

Answers (1)

methai
methai

Reputation: 9153

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
});

Upvotes: 2

Related Questions