Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 692
kevin_song Avatar asked Jul 24 '14 07:07

kevin_song


People also ask

How do I debug node memory leaks?

A quick way to fix Node. js memory leaks in the short term is to restart the app. Make sure to do this first and then dedicate the time to seek out the root cause of the memory leak.

How do I debug node service?

Open the starting file (typically index. js ), activate the Run and Debug pane, and click the Run and Debug Node. js (F5) button. The debugging screen is similar to Chrome DevTools with a Variables, Watch, Call stack, Loaded scripts, and Breakpoints list.


2 Answers

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 () { 
like image 153
B T Avatar answered Oct 12 '22 09:10

B T


For me the why-is-node-running package was not very useful since I had an infinite while loop.
I wish there was a tool that will detect infinite loop all around the project.
What solve for me the issue was to manually reverse some versions of my project and to manually re-add the code I deleted, until I found out what cause my application to hangs, as I said, a infinite while loop.

like image 43
Or Assayag Avatar answered Oct 12 '22 08:10

Or Assayag