6

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?

2
  • Nope, I'm still searching for a solution, will update once I figure this thing out. Commented Sep 5, 2011 at 15:05
  • FYI you can node debug script which allows you to step through and set breakpoints via commandline: nodejs.org/api/debugger.html Commented Jul 7, 2017 at 0:52

3 Answers 3

4

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 :)

Sign up to request clarification or add additional context in comments.

2 Comments

It was an evetemitter that ended up using it's own event. Quite silly, but given the code base size, understandable
I had/have a similar problem, where sometimes (!) only Firefox (!) created an infinite request loop. Does not happen on any other browser and only on Desktop device. Quite confusing, but maybe the debug mode will help.
1

If node-inspector doesn't work for you for some reason (it doesn't for me), but you can easily reproduce the bug, try running node --prof script, wait until it freezes and then a few more minutes, then just run node-tick-processor and see which function has the most ticks.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.