I seem to have an infinite loop somewhere in my node.js program. CPU goes up to 99.9% and the server just freezes.
Is there any way to break when the server freezes and then check the call stack to see what function is causing this?
So, I figured out a solution.
I installed node-inspector (awesome piece of work BTW) and compiled node in debug mode.
Don't forget to activate it: node-inspector & will run it in the background.
After that I started the node process with V8's debug flag:
node --debug script.js
The tricky part was getting the infinite loop to reappear, but after 20 minutes or so I lucked out and it did. I used the inspector's interface to pause the program (pause button on the right hand side) and then check out where the stack is currently is. Sometimes the pause will occur in native code but you can pause and resume it until you go back to the JavaScript.
Success :)
No, I don't think this is possible. Of course, you can add breakpoints but you must place them at points where you suspect where the infinite loop is running...after that, you can manually check what is happening. Also, you can add some line of code that is writing something to the screen or a textsfile as it hits the line. If you see some repeating line, you know where to look.
node debug scriptwhich allows you to step through and set breakpoints via commandline: nodejs.org/api/debugger.html