4

I have a node.js program that's hanging after completing everything I want it to do. I'm fairly certain it is an open connection somewhere that is keeping the program from exiting. Is there a way to tell/debug what is keeping the program from exiting?

Unnecessary edit: This question is in no way similar to my question: How do I debug Node.js applications? . Thanks for playing tho..

Community
  • 1
  • 1
B T
  • 46,771
  • 31
  • 164
  • 191
  • possible duplicate of [How to debug Node.js applications](http://stackoverflow.com/questions/1911015/how-to-debug-node-js-applications) – thefourtheye May 31 '15 at 07:57
  • @thefourtheye That question is far far too general to be a duplicate of this one. – B T May 31 '15 at 07:57
  • 1
    Whats the code for your connections, does this sort of thing help: http://stackoverflow.com/questions/7348736/how-to-check-if-connection-was-aborted-in-node-js-server – n34_panda May 31 '15 at 08:06
  • @n34_panda No, I know how to correctly catch both normal closes and unclean closes. My problem is that the connection *isn't* being closed, but I don't know which connection it is, or even whether its a connection for sure. Ideally, I could imagine some kind of way to ask node "how many things are keeping the application alive, and what kind of 'things' are they (type [network, file system file, input descriptor], name ["http connection to ], etc). – B T May 31 '15 at 10:59
  • 1
    To all those who seems to miss the point. This question is asking about event loop introspection. Which is something I believe is missing in javascript. Not sure if there are extensions to node.js that provides event loop introspection. FWIW, one of the only other language with a built-in event loop, tcl, does indeed have introspection for various things that hook into the event loop like listing all open file descriptors, listing all waiting timers (setTimeout/setInterval) etc. – slebetman May 31 '15 at 13:47
  • @slebetman What are the names of the functions that do those things in TCL? – B T Aug 24 '15 at 19:44
  • @BT: The most direct equivalent to what you're asking for is the `file channels` command (the `channels` method of the `file` "object"). It accepts a glob-style argument (for example `file*` or `socket*`) to list all open filehandles. If no argument is given it defaluts to `*`. There's also `chan names` which does the same except it applies to all channels, not just filehandles. In tcl, channels are like streams in node: they don't have to be real files or sockets, they can be virtually implemented by functions. – slebetman Aug 25 '15 at 01:56
  • See: https://www.tcl.tk/man/tcl8.6/TclCmd/file.htm#M9, https://www.tcl.tk/man/tcl8.6/TclCmd/chan.htm#M27 for documentation on the tcl functions mentioned above – slebetman Aug 25 '15 at 01:58
  • This question is related to mine: http://stackoverflow.com/questions/30757182/how-to-access-the-event-loop-from-node-js-code/30757374#30757374 – B T Aug 25 '15 at 03:28
  • 1
    try using [why is node running] module to debug https://nmotw.in/why-is-node-running/ – actor203 May 03 '16 at 16:58
  • 1
    @actor203 You should make that an answer! – B T May 12 '16 at 00:27

1 Answers1

1

There is an npm module Why is node running module which helps in "Node is running but you don't know why?"

actor203
  • 158
  • 1
  • 8