Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximum call stack size exceeded #692

Closed
mikeumus opened this issue Oct 30, 2013 · 39 comments
Closed

Maximum call stack size exceeded #692

mikeumus opened this issue Oct 30, 2013 · 39 comments

Comments

@mikeumus
Copy link
Member

I introduced multiple collections that use the findAll $exists and then this error came around. Our local DocPad projects get past the error sometimes but then whenever anyone new pulls down from git the issue emerges again. The project in question:
https://github.com/MassDistributionMedia/arkivum.docpad
Running Node@0.10.21 and DocPad@6.54.2
(The node error was seen in node@0.10.7 as well)

info: Welcome to DocPad v6.54.2 (local installation: c:\Users\Michael\Desktop\MD
M\Client Projects\Arkivum.com\Development\Staging\node_modules\docpad)
info: Contribute: http://docpad.org/docs/contribute
info: Plugins: cleanurls, coffeescript, eco, ghpages, iconmonstr, livereload, ma
rked, menu, partials, related, text
info: Environment: development
info: DocPad listening to http://localhost:9778/ on directory c:\Users\Michael\D
esktop\MDM\Client Projects\Arkivum.com\Development\Staging\out
info: LiveReload listening to new socket on channel /docpad-livereload
Currently on renderFiles (pass 1) at 24/54 44% =====================------------
----------------
node.js:0
// Copyright Joyent, Inc. and other Node contributors.
^
RangeError: Maximum call stack size exceeded
An error occured within the child DocPad instance: exited with a non-zero status
 code
@mikeumus
Copy link
Member Author

Pardon I can't give more information than that. It's either an issue of not pulling/pushing with git properly or it really doesn't like my collections I'm using here: https://github.com/MassDistributionMedia/arkivum.docpad/blob/master/docpad.coffee#L79

@pflannery
Copy link
Contributor

I had the same error message a couple of days ago but it was appearing just after docpad reported "Shutting down... cya next time!" (during a "docpad generate")

I believe this may of been because one of my plugins wasn't calling next() at the right time during the renderAfter event.

I'm not sure if this has fixed the problem because it was intermittently happening but I haven't seen it come back since so I guess time will tell.

@mikeumus
Copy link
Member Author

Hey @pflannery, thanks for your instance of the issue.
Yeah it's a hard bug to pin down as there's not much to go off.

@mikeumus
Copy link
Member Author

Seems if I make minor changes to the files that use the new collections, save, and then docpad run it's slow on the 2 passes (generation) but get through them successfully. Odd.

@mikeumus
Copy link
Member Author

Actually these files have to be modified and saved over every time a change is made to any other file so this is a rather crippling issue in my instance.

@pflannery
Copy link
Contributor

I get the "stack size exceeded" error with your repo and found that if I make the default.html.eco layout blank the error goes away.

So i put the default.html.eco back to its original state and then put a try catch in to the eco-plugin.js file (in node_modules) and this is what it spat out

Currently on renderFiles (pass 1) at 24/54 44% =====================----------------------------Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Currently on renderFiles (pass 1) at 36/54 67% ================================-----------------Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Currently on renderFiles (pass 2) at 3/33 9% ====---------------------------------------------Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Currently on renderFiles (pass 2) at 15/33 45% ======================---------------------------Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners
Item duplicate: /pages/partners

I've not yet looked at the reason why these duplicate messages are happening but it seems this is why docpad is quitting with the "stack size exceeded"..

@pflannery
Copy link
Contributor

I've found that this Item Duplicate message is thrown by the method called @generateMenu in the partial called left-sidebar.html.eco...that method itself is from the docpad-plugin-menu...

@pflannery
Copy link
Contributor

last but not least, this is the line of code that is blowing up docpad's asynchronous rendering - https://github.com/sergeche/docpad-plugin-menu/blob/master/src/menu.plugin.coffee#L45

It seems that the throw command is killing docpad without letting it know first...

I believe it maybe better for this plugin to bubble the error up to docpad so it can quit the asynchronous render call stack, clean up resources and display the error it generated (would have to confirm this with Mr @balupton )

@balupton
Copy link
Member

I'd raise it with the author, seems that the purpose there is to just not add duplicate menu entries, in which case that throw should just be a break. No need to throw if a duplicate is found, just don't add it.

@sergeche can you look into this?

@pflannery
Copy link
Contributor

Out of curiosity Is their a way to bubble up exceptions during render from inside a template. For instance if someone is using docpad generate during deployment and they detect an eco sidebar has an issue can we tell docpad to spit out a message, halt processing and fail the build?

In this current case the build would fail but we don't know why it failed on the other hand we could instead write out a duplicate item message for each failure but the build wouldn't fail and docpad would generate missing content leaving us to manually determine something went wrong.

@balupton
Copy link
Member

I'm getting this too on the bevry website all of a sudden...

@balupton
Copy link
Member

Try this: docpad run --global -d and check the result for errors

@mikeumus
Copy link
Member Author

The debug stops and the node error outputs at the ...\partners\tech\index.html file:

debug: Load document: c:\Users\Michael\Desktop\MDM\Client Projects\Arkivum.com\D
evelopment\Staging\src\documents\pages\partners\tech\index.html
    → [2013-10-30 21:44:45.132] [c:\Users\Michael\AppData\Roaming\npm\node_modul
es\docpad\out\lib\docpad.js] [DocumentModel.<anonymous>]

node.js:0
// Copyright Joyent, Inc. and other Node contributors.
^
RangeError: Maximum call stack size exceeded

Which the file is not seemingly unique:
https://github.com/MassDistributionMedia/arkivum.docpad/blob/master/src/documents/pages/partners/tech/index.html

@mikeumus
Copy link
Member Author

DocPad.org doesn't use the menu plugin so what's your debug telling you @balupton?

@balupton
Copy link
Member

Just had access to a variable of an undefined object. Fixing that fixed the maximum call stack size exceeded.

@mikeumus
Copy link
Member Author

@balupton, Good to hear.

@pflannery, any top-of-the-hat ideas on how to patch menu?

@balupton
Copy link
Member

Encountered this again. Running in Node v0.8.26 instead of v0.10.21 gave a more useful error message. Perhaps that will help.

@pflannery
Copy link
Contributor

I believe you could utilize the add event in your left_sidebar_menu collection code and then make sure that each url is unique

something like this (i've not tried this code)

# Menu drop down collections
    left_sidebar_menu: (database) ->
        database.findAllLive({tags:$has:'left_sidebar_menu-item'}, [date:-1])
        .on('add', (model) ->
          model.setDefaults 
            url: # something unique for each url goes here
          )

@mikeumus
Copy link
Member Author

Thanks @pflannery for the lead. I'll work with this today.

@balupton, if the error is showing again for another issue, maybe it's also something to do with DocPad@6.54.1 which is when it seems to have started showing up (Is this when it first showed for you too @pflannery?).

It's good that this is telling use to debug and fix things but having DocPad send out a message as @pflannery was saying giving us more information about the issue as well as stepping around it may be the way to go.

@pflannery
Copy link
Contributor

first time I saw this was in v6.53.4

@balupton
Copy link
Member

Yes. Having a message caught is the ideal. Node 0.8 catches the message successfully, but for some reason Node 0.10 doesn't. I'll be looking into this more tomorrow.

@nfriedly
Copy link
Contributor

nfriedly commented Nov 2, 2013

Just thought I'd chime in here to mention that there seem to be a couple of other scenarios that also cause the Maximum call stack size exceeded error:

<%- @getBlock('scripts').add(['/vendor/foundation.min.js',
'/vendor/audiolib.js','/vendor/freqfinder.js','/vendor/modernizr.js']).toHTML() %>

(With a line break in there)

And

<%- @getBlock("scripts").add( @getDocument().get('scripts') ).toHTML() %>

When scripts metadata is undefined. The later one worked in v6.53.4 and was broken after I updated to v6.54.0.

Related: http://stackoverflow.com/questions/19710214/rendering-error-rangeerror-maximum-call-stack-size-exceeded/19720831#19720831

@pflannery
Copy link
Contributor

Yeah "Maximum call stack size exceeded." seems to happen with any unhandled error..
maybe worth keeping this issue open until it's resolved?

@balupton
Copy link
Member

balupton commented Nov 4, 2013

I made this change to taskgroup recently, however I don't see any change there that could cause such an issue:
bevry/taskgroup@b83899b

@ofShard
Copy link

ofShard commented Nov 4, 2013

From stepping through the code with node-inspector, it seems to be cyclically handling then re-emitting the error event in the taskgroup module. Specifically https://github.com/bevry/taskgroup/blob/master/src/lib/taskgroup.coffee

In my test, it was in the TaskGroup constructor, and in the bubbleEvents code for addTask and addItem. My test used the 3.2.4 version of taskgroup though. You changed some of that in 3.3.0, so I'll see if it's fixed.

@balupton
Copy link
Member

balupton commented Nov 5, 2013

Is it possible for you to add a test case that reproduces the issue within taskgroup? That would be sweet! From there, we can work together on fixing the issue.

@pflannery
Copy link
Contributor

This tiny docpad project recreates the error - https://github.com/pflannery/docpad-callstack-err

The error occurs in the "docpad\node_modules\event-emitter-grouped\node_modules\taskGroup@3.2.4"

It seems to be repeatedly going through these steps:
{
first calls here
https://github.com/bevry/taskgroup/blob/master/src/lib/taskgroup.coffee#L98
here
https://github.com/bevry/taskgroup/blob/master/src/lib/taskgroup.coffee#L358
then here
https://github.com/bevry/taskgroup/blob/master/src/lib/taskgroup.coffee#L253
repeat
eventually "Maximum call stack size exceeded"
}

@balupton
Copy link
Member

balupton commented Nov 5, 2013

Sweet thanks. Will look into it tomorrow. In say 12 hours. By all means, keep looking into it in the meantime.

TraceGL or Webkit Inspector should help.

@pflannery
Copy link
Contributor

So far I see that when this me.emit('error', err) is called the me._events object doesn't contain an "error" function so this causes events.js to throw an error which in turn causes the uncaughtExceptionCallback to fire again thus the loop...

so if we give TaskGroup an "error" event it should stop this loop.

@balupton
Copy link
Member

balupton commented Nov 6, 2013

Was able to finally reproduce this today, looking into it now:

events.js:71
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: Uncaught, unspecified 'error' event.
    at TaskGroup.EventEmitter.emit (events.js:73:15)
    at TaskGroup.setConfig.opts (/Users/balupton/Projects/docpad/node_modules/safefs/node_modules/taskgroup/out/lib/taskgroup.js:210:19)
    at TaskGroup.EventEmitter.emit (events.js:99:17)
    at TaskGroup.addItem (/Users/balupton/Projects/docpad/node_modules/safefs/node_modules/taskgroup/out/lib/taskgroup.js:285:26)
    at Task.EventEmitter.emit (events.js:126:20)
    at Task.uncaughtExceptionCallback (/Users/balupton/Projects/docpad/node_modules/safefs/node_modules/taskgroup/out/lib/taskgroup.js:84:12)
    at Domain.EventEmitter.emit (events.js:96:17)
    at TaskGroup.EventEmitter.emit (events.js:66:21)
    at TaskGroup.setConfig.opts (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:264:19)
    at TaskGroup.EventEmitter.emit (events.js:99:17)
    at TaskGroup.addItem (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:393:26)
    at Task.EventEmitter.emit (events.js:126:20)
    at Task.uncaughtExceptionCallback (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:117:12)
    at Domain.EventEmitter.emit (events.js:96:17)
    at TaskGroup.EventEmitter.emit (events.js:66:21)
    at TaskGroup.setConfig.opts (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:264:19)
    at TaskGroup.EventEmitter.emit (events.js:99:17)
    at TaskGroup.addItem (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:393:26)
    at Task.EventEmitter.emit (events.js:126:20)
    at Task.uncaughtExceptionCallback (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:117:12)
    at Domain.EventEmitter.emit (events.js:96:17)
    at TaskGroup.EventEmitter.emit (events.js:66:21)
    at TaskGroup.setConfig.opts (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:264:19)
    at TaskGroup.EventEmitter.emit (events.js:99:17)
    at TaskGroup.addItem (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:393:26)
    at Task.EventEmitter.emit (events.js:126:20)
    at Task.uncaughtExceptionCallback (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:117:12)
    at Domain.EventEmitter.emit (events.js:96:17)
    at TaskGroup.EventEmitter.emit (events.js:66:21)
    at TaskGroup.setConfig.opts (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:264:19)
    at TaskGroup.EventEmitter.emit (events.js:99:17)
    at TaskGroup.addItem (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:393:26)
    at Task.EventEmitter.emit (events.js:126:20)
    at Task.uncaughtExceptionCallback (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:117:12)
    at Domain.EventEmitter.emit (events.js:96:17)
    at TaskGroup.EventEmitter.emit (events.js:66:21)
    at TaskGroup.setConfig.opts (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:264:19)
    at TaskGroup.EventEmitter.emit (events.js:99:17)
    at TaskGroup.addItem (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:393:26)
    at Task.EventEmitter.emit (events.js:126:20)
    at Task.uncaughtExceptionCallback (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:117:12)
    at Domain.EventEmitter.emit (events.js:96:17)
    at TaskGroup.EventEmitter.emit (events.js:66:21)
    at TaskGroup.setConfig.opts (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:264:19)
    at TaskGroup.EventEmitter.emit (events.js:99:17)
    at TaskGroup.addItem (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:393:26)
    at Task.EventEmitter.emit (events.js:126:20)
    at Task.uncaughtExceptionCallback (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:117:12)
    at Domain.EventEmitter.emit (events.js:96:17)
    at TaskGroup.EventEmitter.emit (events.js:66:21)
    at TaskGroup.setConfig.opts (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:264:19)
    at TaskGroup.EventEmitter.emit (events.js:99:17)
    at TaskGroup.addItem (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:393:26)
    at Task.EventEmitter.emit (events.js:126:20)
    at Task.uncaughtExceptionCallback (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:117:12)
    at Domain.EventEmitter.emit (events.js:96:17)
    at TaskGroup.EventEmitter.emit (events.js:66:21)
    at TaskGroup.setConfig.opts (/Users/balupton/Projects/docpad/node_modules/event-emitter-grouped/node_modules/taskgroup/out/lib/taskgroup.js:210:19)
    at TaskGroup.EventEmitter.emit (events.js:99:17)
    at TaskGroup.addItem (/Users/balupton/Projects/docpad/node_modules/event-emitter-grouped/node_modules/taskgroup/out/lib/taskgroup.js:285:26)
    at Task.EventEmitter.emit (events.js:126:20)
    at Task.uncaughtExceptionCallback (/Users/balupton/Projects/docpad/node_modules/event-emitter-grouped/node_modules/taskgroup/out/lib/taskgroup.js:84:12)
    at Domain.EventEmitter.emit (events.js:96:17)
    at Task.EventEmitter.emit (events.js:66:21)
    at Task.uncaughtExceptionCallback (/Users/balupton/Projects/docpad-sites/conf-boilerplate/node_modules/docpad-plugin-partials/node_modules/taskgroup/out/lib/taskgroup.js:84:12)
    at Domain.EventEmitter.emit (events.js:96:17)
    at TaskGroup.EventEmitter.emit (events.js:66:21)
    at TaskGroup.setConfig.opts (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:264:19)
    at TaskGroup.EventEmitter.emit (events.js:99:17)
    at TaskGroup.addItem (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:393:26)
    at Task.EventEmitter.emit (events.js:126:20)
    at Task.uncaughtExceptionCallback (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:117:12)
    at Domain.EventEmitter.emit (events.js:96:17)
    at TaskGroup.EventEmitter.emit (events.js:66:21)
    at TaskGroup.setConfig.opts (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:264:19)
    at TaskGroup.EventEmitter.emit (events.js:99:17)
    at TaskGroup.addItem (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:393:26)
    at Task.EventEmitter.emit (events.js:126:20)
    at Task.uncaughtExceptionCallback (/Users/balupton/Projects/docpad/node_modules/taskgroup/out/lib/taskgroup.js:117:12)
    at Domain.EventEmitter.emit (events.js:96:17)
    at TaskGroup.EventEmitter.emit (events.js:66:21)
    at TaskGroup.setConfig.opts (/Users/balupton/Projects/docpad/node_modules/event-emitter-grouped/node_modules/taskgroup/out/lib/taskgroup.js:210:19)
    at TaskGroup.EventEmitter.emit (events.js:99:17)
    at TaskGroup.addItem (/Users/balupton/Projects/docpad/node_modules/event-emitter-grouped/node_modules/taskgroup/out/lib/taskgroup.js:285:26)
    at Task.EventEmitter.emit (events.js:126:20)
    at Task.uncaughtExceptionCallback (/Users/balupton/Projects/docpad/node_modules/event-emitter-grouped/node_modules/taskgroup/out/lib/taskgroup.js:84:12)
    at Task.fire (/Users/balupton/Projects/docpad/node_modules/event-emitter-grouped/node_modules/taskgroup/out/lib/taskgroup.js:127:24)
    at Domain.bind.b (domain.js:201:18)
    at Domain.run (domain.js:141:23)
    at Task.fire (/Users/balupton/Projects/docpad/node_modules/event-emitter-grouped/node_modules/taskgroup/out/lib/taskgroup.js:121:23)
    at process.startup.processNextTick.process._tickCallback (node.js:245:9)

@balupton
Copy link
Member

balupton commented Nov 6, 2013

Making good progress.

@balupton
Copy link
Member

balupton commented Nov 6, 2013

Got the fix ready, but the jade plugin is failing with the changes. Debugging.

@balupton
Copy link
Member

balupton commented Nov 6, 2013

Will pick this up tomorrow, got late here. Pushed my changes up to the issue-692 branch. If someone would like to debug the failing tests of the jade plugin, that would be great.

@balupton
Copy link
Member

balupton commented Nov 7, 2013

Fix released to DocPad v6.54.5. Thanks everyone for your assistance and help on this! Great team effort! :)

Be sure to run docpad update in your project too.

@pflannery
Copy link
Contributor

👍

@mikeumus
Copy link
Member Author

mikeumus commented Nov 7, 2013

Cheers! 👍

@ofShard
Copy link

ofShard commented Nov 7, 2013

I haven't managed to come up with a simple test case yet using only taskgroup. Since you seem to have this issue figured out already, I won't look into it anymore.

@balupton
Copy link
Member

balupton commented Nov 7, 2013

The crux of the issue was in two parts:

  1. When an uncaught exception happens in a Task, it emitted an error event, that was then caught by the parent task's domain catcher, and process repeats. It isn't an infinite issue as suspected, but just a chain of many tasks in tasks. Hence trying to catch this with a straightforward unit test would be quite difficult, as the bubbling up would work. The solution I applied was having the TaskGroup handle uncaught exceptions by stopping the queue and using the completion callback to report. Rather than the TaskGroup emitting the error event as well.
  2. The other issue is that the Partials Plugin had no way of reporting errors to the user safely. This has been resolved.

@pflannery
Copy link
Contributor

@balupton you mentioned Webkit Inspector, how are you using this with nodejs? is it via the webkit-devtools-agent?

I cant seem to connect when trying to run this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants