3

My co-workers and I have written a node.js application. I was assigned to debug an issue this week. The issue is that the application crashes every few days with this error:

events.js:0
(function (exports, require, module, __filename, __dirname) { // Copyright Joy
^
RangeError: Maximum call stack size exceeded

Unfortunately it doesn't print anything else.

What node.js methods and tools could I use with node.js to debug this issue? Our application is really huge (it powers the entire campus document finder) so we don't know where this error is happening exactly (there are many files of source code).

twasbrillig
  • 17,084
  • 9
  • 43
  • 67
bodacydo
  • 75,521
  • 93
  • 229
  • 319
  • 1
    http://stackoverflow.com/questions/6095530/maximum-call-stack-size-exceeded-error – laggingreflex Oct 19 '14 at 07:03
  • from the error it seems that an event emitter emits an event when this event is emitted, I mean that the event is triggered by itself, with some code example I could say more. Try node-inspector to debug – micnic Oct 22 '14 at 07:41
  • I had a very similar issue a while ago in a very simple app. Do not remember well, but I think it was even caused by `event.js`, as well. I had `process.on('uncaughtException', ...)` set but the error was not caught there. I was able to reproduce the error, but it did not make any sense (to me at least). I thought it was some `node.js` external bug, so start using an older version (0.8.x instead of 0.10.2x). The error disappeared. After a couple of weeks and reboots I decided to try 0.10.2x again. There was no error any more -- though my code was exactly the same as before. – artur grzesiak Oct 23 '14 at 13:09
  • See this post http://stackoverflow.com/questions/7663957/debugging-maximum-call-stack-size-exceeded – ppascualv Oct 27 '14 at 16:41
  • Some other approaches you might look in to are discussed here: http://stackoverflow.com/questions/591857/how-can-i-get-a-javascript-stack-trace-when-i-throw-an-exception – Randy Childers Oct 28 '14 at 13:58
  • Do you use Mongoose? – UpTheCreek Jun 25 '15 at 12:36

2 Answers2

3

From your description (that it crashes, predictably, every few days -- presumably after the same amount of time), it sounds like there may be a thread whose stack is growing over time through recursion. To see this, I'd wait for a day or so and then use ProcDump to force a core dump of whatever container application is actually executing the javascript. Open the core file up in something like WinDbg and look for the thread with the ridiculous number of stack frames -- that could shed some light on your problem.

  • On my way home last night, I realized this probably won't work, as the javascript is interpreted, not compiled, so the container running it won't have the sort of stack trace I was imagining, but this approach may not be a total loss. After you collect the core dump, try running it through the utility "strings", which will pull out the ASCII strings in the dump. I would expect that a javascript interpreter would have copies of the interpreted line in memory, and that if it were recursing, there would be a LOT of copies of that line -- so look for thousands of copies of the same js line. – Randy Childers Oct 28 '14 at 13:38
  • Hi Randy, I didn't quite figure it out yet but I'll award you the bounty. I and my co workers will try to figure it out using your method. Thanks. – bodacydo Oct 29 '14 at 09:36
  • Thank you bodacydo, and good luck. One more note: if the system you're using is Unicode, and not ASCII, then you'll need to use a strings utility that understands Unicode -- I'd suggest the Sysinternals strings.exe available from Microsoft. – Randy Childers Oct 29 '14 at 13:37
1

If you have no tools, create one. You should count function calls by values, I mean you should insert something like this inside the function:

function(...) {
  callCounter[module]++;
  console.log("module:",module,"count:",callCounter[module]);
    ...
  callCounter[module]--;
} // fn()

Yes, it will flood the screen, (EDIT:) so you may capture it. (This half sentence disappeared somehow, re-added days later.)

ern0
  • 3,074
  • 25
  • 40