Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.JS: Tool to see why process is still running?

Is there a way to see what timeouts, intervals or async operations (or endless loops) are still running and are stopping my process from ending?

I have been able to figure it out so far without such a tool, but such a tool would be very handy especially as the Node.JS projects here start to get bigger.

I am thinking of Java's kill -3 which prints a stack trace to stderr. You can do this for any process, any time, debug or no. I would like an equivalent for Node.JS. (I know that node is single threaded with async so it would output differently)

like image 410
700 Software Avatar asked May 06 '11 19:05

700 Software


People also ask

How do you handle a long running process in node js?

Hence, the solution is: (1) use a nodejs server that does nothing but queue tasks in the worker queue. (2) use a nodejs worker queue (like kue ) to do the actual work. Use cluster to spread the work across different CPUs. The result is a simple, single server that can handle hundreds of requests (w/o choking).

How do I check if node is running?

Just incase you are not bound to nodejs, from linux command line you can also do ps -ef | grep "YOUR_PROCESS_NAME_e. g. _nodejs" to check for a running process.

What is node js and why is it running?

Node. js is a single-threaded, open-source, cross-platform runtime environment for building fast and scalable server-side and networking applications. It runs on the V8 JavaScript runtime engine, and it uses event-driven, non-blocking I/O architecture, which makes it efficient and suitable for real-time applications.


1 Answers

The module why-is-node-running is exactly the thing you need.

 var log = require('why-is-node-running')
 setTimeout(function () {
   log() // logs out active handles that are keeping node running
 }, 100)

And the output is something 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 64
B T Avatar answered Sep 19 '22 18:09

B T