It says on the Node.js about page:
Node exits the event loop when there are no more callbacks to perform.
Is there a way to find out which callbacks are keeping Node from exiting?
It says on the Node.js about page:
Node exits the event loop when there are no more callbacks to perform.
Is there a way to find out which callbacks are keeping Node from exiting?
You can use process._getActiveHandles()
and process._getActiveRequests()
See this discussion in node.js mailing list.
update: there is a good package for this - https://github.com/mafintosh/why-is-node-running
"totally spacing on the name, it's like "process._getOpenHandles()" or something equally hard to remember"
. I was Googling around trying to find the actual call and couldn't. Thanks again. –
Winser node_globals.js
and didn't find it. Now I am grepping the node codebase, knowing what to look for, and find that they're defined in node.cc. process._getActiveHandles() is src/node.cc:2345: NODE_SET_METHOD(process, "_getActiveHandles", GetActiveHandles);
Hah! Excellent. –
Winser There is a npm module wtfnode to show what keep the nodejs app running when you sends SIGINT (ctrl-c) to it.
It internal uses process._getActiveHandles()
as mentioned in @andrey-sidrov's answer. The benefit of using wtfnode
is that it provides easy-to-read output.
If you are interested to find out which open connections are still open:
While the process hangs, you can run in mac and linux: netstat -a
to search for open ports. It's a good clue that helps me from time to time when it comes to why Jest is hanged.
© 2022 - 2024 — McMap. All rights reserved.