Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging "Maximum call stack size exceeded"

Tags:

I have a server that I can cause to die with the following output:

events.js:38 EventEmitter.prototype.emit = function(type) {                                   ^ RangeError: Maximum call stack size exceeded 

However, without a stack dump or trace, I have no way of finding whether this is infinite recursion or just a slightly-too-large chain, let alone where the problem function is.

Running Node with the --trace option caused my tests to not only run slow (as one would expect), but to not reproduce the problem.

Anybody have any solutions or tips for getting to the bottom of this?

like image 478
OrangeDog Avatar asked Oct 05 '11 15:10

OrangeDog


People also ask

How do you debug an error in maximum call stack size exceeded?

The most common way to fix this error is to reduce the number of function calls, or to limit the number of variables that are created. Another option is to use a tracer debugger to keep track of the program's state and find the function that's causing the error.

What does it mean when maximum call stack size exceeded?

The JavaScript exception "too much recursion" or "Maximum call stack size exceeded" occurs when there are too many function calls, or a function is missing a base case.

What is maximum call stack?

It means that somewhere in your code, you are calling a function which in turn calls another function and so forth, until you hit the call stack limit. This is almost always because of a recursive function with a base case that isn't being met.

What does error RangeError maximum call stack size exceeded see JavaScript console for details?

The "RangeError: Maximum call stack size exceeded" error occurs when a function is called so many times that the invocations exceed the call stack limit. To solve the error, specify a base case that has to be met to exit the recursion.


2 Answers

It seems the answer is currently: sit tight and wait for Node.js to update to a newer V8 version, or build your own with the patch from this Chromium project bug report.

This archived thread from the v8-dev mailing list shows a discussion in which

  • Dave Smith brings up this very issue and proposes a patch
  • Yang Guo of the Chromium project discusses it, files a Chromium bug against the issue, and applies a different fix
  • Dave notes that Node (0.8 at the time) is using V8 3.11 and asks about backporting the patch. Yang replies that the patch will probably land in V8 3.15 and will not be backported.

Note that Node.js v0.8 used V8 3.11; Node.js 0.10 is currently using V8 3.14. So the patch accepted by Chromium for this issue is still "in the future" as far as Node is concerned.

(This answer owes thanks to @Coderoshi, since it's by following the thread from his answer that I learned all this.)

like image 54
metamatt Avatar answered Feb 01 '23 23:02

metamatt


The chance of it being a "slightly-too-large chain" seems unlikely.

It's probably a function calling the event that triggered itself.

So if the slowing down of the code is making the infinite recursion to stop. My guess would be that you have a queue and with the slower mode its not getting filled up as fast.

If this doesn't help then I think I need more info. Maybe someone has a catch-all for this though.

like image 41
megakorre Avatar answered Feb 01 '23 22:02

megakorre