调试node.js进程的最佳实践?

时间:2013-07-29 21:47:11

标签: node.js libuv

我的node.js服务器获得了大量的EMFILE,并最终因libuv无法创建kqueue()而中止。所以,我希望看到它发生时会打开的是什么。我写了附加的脚本,它会分叉服务器,等待它崩溃,然后运行'lsof -p'。

我对文档的理解是,当一个fork'd子项退出时,它会一直存在,直到process.exit()发生。这很好,因为lsof将能够在它被擦除之前询问僵尸的描述符:

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

然而,对exec()lsof的调用总是使用error参数调用回调(lsof包永远不会检查):

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

但是,也许我正在以错误的方式看待这个问题。这方面的最佳做法是什么?

1 个答案:

答案 0 :(得分:1)

  

我对文档的理解是,当一个分叉的孩子退出时

这是不正确的。您阅读了哪些文档,我们可以帮助更新以使其更清晰?

相关问题