Let me explain first what I mean by "exiting cleanly".
If I have a nodejs app and I do setTimeout for a really long time, or if I open a socket connection that I don't close, then when I run that app it will not exit. The reason is quite clear and a good one I think, the way nodejs works is to wait until there is "no more work to do", sort of, and then it exits. That's good and I like that way of operation. It also forces me to be a bit disciplined about closing sockets cleanly and not having timers lying around. Another good thing.
However, I have the problem that I have been given some code that does not adhere to this discipline, and it does not exit cleanly. I suspect that the code somewhere leaves an open socket, but the code is minified so it's not that easy to find the point where this socket is opened.
My question is, is there a way I can query nodejs to find out which sockets are open? By seeing such a list with ip numbers and such I could start digging to find out where the code is that opens them.
I wrote a package to help with this: wtfnode
I stumbled on this question while trying to figure out why I get as many downloads as I do; while this question is very old now, I figure maybe this will help someone in the future searching for similar terms.
Without more information from your original post, it's hard to say what your specific problem was, but one possibility is lingering sockets due to HTTP keep-alive (either as a client or server).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With