【问题标题】:best practices for debugging a node.js process?调试 node.js 进程的最佳实践?
【发布时间】:2013-07-29 21:47:10
【问题描述】:

我的 node.js 服务器收到大量 EMFILE,最终由于 libuv 无法创建 kqueue() 而中止。所以,我想看看发生这种情况时它会打开什么。我编写了附加的脚本,它分叉服务器,等待它崩溃,然后运行'lsof -p'。

我对文档的理解是,当一个分叉的孩子退出时,它会一直存在,直到 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 的调用总是调用带有错误参数的回调(这是 lsof 包从不检查的):

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

但是,也许我看错了。这方面的最佳做法是什么?

【问题讨论】:

    标签: node.js libuv


    【解决方案1】:

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

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

    【讨论】:

    • nodejs.org/api/… 底部写着“子进程完成后不会自动退出,您需要显式调用 process.exit()。此限制将来可能会取消。”
    • 我想知道这到底是怎么发生的,但为什么要在嘴里看一匹礼物马(-;
    • 让我们忽略这种方法。有没有人知道我如何检查一个中止的节点进程(例如,由于我上面描述的 libuv 断言)?
    猜你喜欢
    • 1970-01-01
    • 2015-04-23
    • 2016-05-19
    • 2014-10-24
    • 2016-01-15
    • 2013-09-24
    • 2020-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多