Nodejs进程挂起,如何调试或收集转储?

21

我在Linux上运行的node.js进程现在挂起了,而且CPU占用率达到了100%。有没有办法调试并找出原因?我需要收集转储文件吗?谢谢。


也许这会有用 https://www.joyent.com/blog/mdb-and-node-js - raidendev
1
请查看https://dev59.com/NXI-5IYBdhLWcg3wVWti#16512303。 - Matt Harrison
此外,您始终可以运行 strace - Nitzan Shaked
@raidendev MDB 可以在 CentOS 中使用吗? - kevin_song
应该尝试使用命令 yum install mdbtools 进行安装。 - raidendev
@raidendev 那是一个不同的软件包,它包含用于处理 MS Access 数据库的工具。 - maccam94
2个回答

17

有一个名为why-is-node-running的npm模块,它可以提供以下信息:

There are 4 known handle(s) keeping the process running and 0 unknown
Known handles:

# Timer
/Users/maf/dev/node_modules/why-is-node-running/example.js:6  - setInterval(function () {}, 1000)
/Users/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()

# TCP
/Users/maf/dev/node_modules/why-is-node-running/example.js:7  - server.listen(0)
/Users/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()

# TCP
/Users/maf/dev/node_modules/why-is-node-running/example.js:7  - server.listen(0)
/Users/maf/dev/node_modules/why-is-node-running/example.js:11 - createServer()

# Timer
/Users/maf/dev/node_modules/why-is-node-running/example.js:13 - setTimeout(function () { 

太好了!现在我知道问题出在哪里了。这正是我一直在寻找的。 - Alexis Wilke
这个工具有助于已经完成工作但没有退出虚拟机的进程。它无法帮助处理无限循环,而这正是这个问题所涉及的。 - Rich

2

对我来说,“why-is-node-running”包并不是很有用,因为我有一个无限循环的while循环。
我希望有一个工具可以检测项目中的无限循环。
解决我的问题的方法是手动反转我的项目的一些版本,并手动重新添加我删除的代码,直到我找到导致应用程序挂起的原因,就像我说的,一个无限循环。


1
为什么没有工具可以检测无限循环:https://en.wikipedia.org/wiki/Halting_problem 我知道这很老了,但只是发帖因为它有点有趣。 - Sam DeSota
1
为什么没有检测无限循环的工具呢:https://en.wikipedia.org/wiki/Halting_problem我知道这是老话题了,但只是发个帖子因为觉得挺有趣的。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接