Nodejs process hang, how could I debug it or collect dump?

kevin_song picture kevin_song · Jul 24, 2014 · Viewed 12k times · Source

my nodejs process which was running at Linux, now it is hang and the CPU is 100%. Is there anyway I can do to debug it and find the reason? Do I need to collect dump and how? Thanks.

Answer

B T picture B T · Nov 18, 2017

There's an npm module called why-is-node-running that can give you info like:

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 () {