1

my node.js server is getting a lot of EMFILEs and eventually aborts due to libuv being unable to create a kqueue(). so, i want to see what it's got open when that happens. i wrote the attached script which forks the server, waits for it to crash, and then runs 'lsof -p'.

my understanding from the docs is that when a fork'd child exits, it's kept around until a process.exit() occurs. that's good, because lsof will be able to interrogate the zombie's descriptors before it gets wiped:

var child_process = require('child_process')

child_process.fork('./index').on('close', function(code, signal) {
  var pid = this.pid;

  if (!!code) console.log('1: exit ' + code); else console.log('1: signal ' + signal);

  console.log('running lsof -p ' + pid);
  child_process.exec('lsof -p ' + pid, function(err, d) {
    if (!!err) { console.log('error:'); console.log(err); }
    if (!!d) console.log('data: ' + d.toString());
  });
}).on('error', function(err) {
  console.log(err.message);
  process.exit(1);
});

however, the call to exec() lsof always invokes the callback with an error parameter (something the lsof package never checks for):

1: signal SIGABRT
running lsof -p 85661
error: { [Error: Command failed: ] killed: false, code: 1, signal: null }

but, maybe i'm looking at this the wrong way. what are the best practices in this area?

1 Answer 1

1

my understanding from the docs is that when a fork'd child exits

That is incorrect. What docs did you read, that we can help update to make it more clear?

Sign up to request clarification or add additional context in comments.

3 Comments

at the bottom of nodejs.org/api/… it says "The child process does not automatically exit once it's done, you need to call process.exit() explicitly. This limitation may be lifted in the future."
i was wondering how that happened exactly, but why look a gift horse in the mouth (-;
let's ignore that approach. does anyone have a pointer as to how i can inspect a node process that aborts (e.g., due to the libuv assertion i describe above)?

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.