RetireJS/grunt-retire

RangeError: Maximum call stack size exceeded

binarykitchen opened this issue · 23 comments

I'm getting this often from Grunt:

/xxx/node_modules/grunt-retire/node_modules/tmp/lib/tmp.js:261
  throw err;
        ^
RangeError: Maximum call stack size exceeded

Using version 0.1.17 here ...

Thanks for reporting!
I've pushed out a new version 0.1.18 where at least if you add "nocache : true" under options in the config, it shouldn't invoke tmp.js. I'll try to fix the real problem later.

Thx but now I get a Warning: Task "retire:files" failed. Use --force to continue. at the end without further information. No idea what failed here.

Can you share your config, and the command used to run it?

When using 0.1.17, was there a stack trace below "RangeError: Maximum call stack size exceeded" ?

No, there was no stack trace. Otherwise I would have posted it already.

My grunt config for retire is simple:

    retire: {
      files: [
        'server/server.js',
        'server/lib/**/*.*',
        'client/scripts/**/*.*'
      ],
      options: {
         verbose: true
      }
    }

Can you please try to put your node directories under "node:" and client side js under "js:", instead of having them mixed under "files:" and see if that helps?

Ah, this worked. Thanks!

False alarm. I still have the error

/home/michael.heuberger/projects/binarykitchen/code/xxx/node_modules/grunt-retire/node_modules/tmp/lib/tmp.js:261
  throw err;
        ^
RangeError: Maximum call stack size exceeded

Reopened.

Can you provide your directory structure (for instance output of ls -R) and your current configuration that gives you this error? As well as node and grunt version (node -v and grunt -v). This will make it easier to reproduce this bug.

ls -R is too long, it's a huge project, so I did a simple ls -lAhG:

# mick at iMac.local in ~/projects/xxx on git:develop o [20:58:21]
$ l
total 144
-rw-r--r--@  1 mick  staff    15K  5 Dec 21:00 .DS_Store
-rw-r--r--   1 mick  staff    44B  8 Nov 18:24 .bowerrc
drwxr-xr-x  14 mick  staff   476B 18 Dec 20:58 .git
-rw-r--r--   1 mick  staff   366B 11 Dec 11:50 .gitignore
-rw-r--r--   1 mick  staff    91B  8 Nov 18:24 .gitmodules
-rw-r--r--   1 mick  staff    57B 11 Dec 11:50 .jsbeautifyrc
-rw-r--r--   1 mick  staff   1.8K  7 Dec 13:18 .jshintrc
-rw-r--r--   1 mick  staff    15K 18 Dec 20:57 Gruntfile.js
-rw-r--r--   1 mick  staff    33B  8 Nov 18:24 LICENSE
-rw-r--r--   1 mick  staff   6.1K 11 Dec 11:50 README.md
drwxr-xr-x   5 root  staff   170B 11 Nov 13:27 auth
-rw-r--r--   1 mick  staff   281B  4 Dec 20:06 bower.json
drwxr-xr-x   8 mick  staff   272B  4 Dec 20:06 client
drwxr-xr-x   6 mick  staff   204B  8 Nov 18:24 docs
drwxr-xr-x  53 mick  staff   1.8K 15 Dec 14:21 node_modules
-rw-r--r--   1 mick  staff   2.6K 18 Dec 20:57 package.json
drwxr-xr-x  11 mick  staff   374B 15 Dec 14:22 server

and

$ node -v
v0.10.22

and

$ grunt --version
grunt-cli v0.1.11
grunt v0.4.2

hope this helps!

I'm guessing this is a problem with the filesystem traversal used to look for files.

Do you have any symlinks in your folder structure? Maybe it goes into a loop...

Thanks, helps a lot. Could you also give the number of files matching: server/lib/**/*.* and client/scripts/**/*.*, maybe you are hitting some limitation on number of files? And your new/current configuration of retire? :) Sorry I'm asking for a lot, but it helps me to understand your problem better.

@eoftedal Nope, there are no symlinks.

@kozmic No problemo, I understand. Here you go:

$ find ./server/lib -type f | wc -l
      49

and

$ find ./client/scripts -type f | wc -l
     877

npm outdated tells me I am using your latest retire version of 0.1.20 ...

@binarykitchen Could you run the same commands with -type d ?

I'm unable to reproduce this locally. I've been running it with 10,000 folders and 100,000 files

And could you post the retire config you get this error with?

Okay, running my usual grunt task for starting the server with grunt server and watching css stuff live with the -D option produces this:

Running "clean:css" (clean) task
[D] Task source: /home/michael.heuberger/projects/binarykitchen/code/signdna/node_modules/grunt-contrib-clean/tasks/clean.js
Cleaning server/public/styles/email.min.css...OK
Cleaning server/public/styles/site.c34dfe67.css...OK
Cleaning server/public/styles/site.min.1ac74557.css...OK

Running "less:<%= project.siteStyles %>" (less) task
[D] Task source: /home/michael.heuberger/projects/binarykitchen/code/signdna/node_modules/grunt-contrib-less/tasks/less.js

Scheduled tasks have been interrupted...OK
>> File "client/styles/imports/item/full.less" changed.

Completed in 0.011s at Thu Dec 19 2013 15:02:13 GMT+1300 (NZDT) - Waiting...
Running "clean:css" (clean) task
[D] Task source: /home/michael.heuberger/projects/binarykitchen/code/signdna/node_modules/grunt-contrib-clean/tasks/clean.js

Running "less:<%= project.siteStyles %>" (less) task
[D] Task source: /home/michael.heuberger/projects/binarykitchen/code/signdna/node_modules/grunt-contrib-less/tasks/less.js
File server/public/styles/site.css created.

Running "less:<%= project.emailStyles %>" (less) task
[D] Task source: /home/michael.heuberger/projects/binarykitchen/code/signdna/node_modules/grunt-contrib-less/tasks/less.js
File server/public/styles/email.css created.

Running "requirejs:siteCSS" (requirejs) task
[D] Task source: /home/michael.heuberger/projects/binarykitchen/code/signdna/node_modules/grunt-contrib-requirejs/tasks/requirejs.js

/home/michael.heuberger/projects/binarykitchen/code/signdna/server/public/styles/site.min.css
----------------
/home/michael.heuberger/projects/binarykitchen/code/signdna/server/public/styles/site.css


Running "requirejs:emailCSS" (requirejs) task
[D] Task source: /home/michael.heuberger/projects/binarykitchen/code/signdna/node_modules/grunt-contrib-requirejs/tasks/requirejs.js

/home/michael.heuberger/projects/binarykitchen/code/signdna/server/public/styles/email.min.css
----------------
/home/michael.heuberger/projects/binarykitchen/code/signdna/server/public/styles/email.css


Running "filerev:css" (filerev) task
[D] Task source: /home/michael.heuberger/projects/binarykitchen/code/signdna/node_modules/grunt-bk-filerev/tasks/filerev.js
✔ server/public/styles/site.css becomes 
  server/public/styles/site.c34dfe67.css
✔ server/public/styles/site.min.css becomes 
  server/public/styles/site.min.1ac74557.css

Running "filerev:js" (filerev) task
[D] Task source: /home/michael.heuberger/projects/binarykitchen/code/signdna/node_modules/grunt-bk-filerev/tasks/filerev.js

Running "filerev:fonts" (filerev) task
[D] Task source: /home/michael.heuberger/projects/binarykitchen/code/signdna/node_modules/grunt-bk-filerev/tasks/filerev.js
7 files unchanged

Running "filerev:images" (filerev) task
[D] Task source: /home/michael.heuberger/projects/binarykitchen/code/signdna/node_modules/grunt-bk-filerev/tasks/filerev.js
11 files unchanged

Running "filerev_assets" task
[D] Task source: /home/michael.heuberger/projects/binarykitchen/code/signdna/node_modules/grunt-filerev-assets/tasks/filerev_assets.js
File server/assets.json created.

Running "clean:withoutVersion" (clean) task
[D] Task source: /home/michael.heuberger/projects/binarykitchen/code/signdna/node_modules/grunt-contrib-clean/tasks/clean.js
Cleaning server/public/styles/site.css...OK
Cleaning server/public/styles/site.min.css...OK
Cleaning server/public/styles/email.css...OK

Running "update_css:src" (update_css) task
[D] Task source: /home/michael.heuberger/projects/binarykitchen/code/signdna/Gruntfile.js

Running "nonzero:src" (nonzero) task
[D] Task source: /home/michael.heuberger/projects/binarykitchen/code/signdna/Gruntfile.js
✔ server/public/scripts/main.min.8bd69d17.js 189486
✔ server/public/styles/email.min.css 3144
✔ server/public/styles/site.c34dfe67.css 90374
✔ server/public/styles/site.min.1ac74557.css 82773

Done, without errors.


Execution Time (2013-12-19 02:02:14 UTC)
loading tasks                      2s  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 79%
less:<%= project.siteStyles %>  362ms  ▇▇▇▇▇▇▇▇▇▇ 13%
requirejs:siteCSS               100ms  ▇▇▇ 4%
Total 3s

/home/michael.heuberger/projects/binarykitchen/code/signdna/node_modules/grunt-retire/node_modules/tmp/lib/tmp.js:261
  throw err;
        ^
RangeError: Maximum call stack size exceeded

I am surprised, grunt retire is not registered in the grunt server task but causes the crash.

And the retire config is:

        retire: {
            node: ['/'],
            client: [
                'client/scripts/config/**/*.*',
                'client/scripts/controllers/**/*.*',
                'client/scripts/fuzzy-circles/**/*.*',
                'client/scripts/util/**/*.*',
                'client/scripts/views/**/*.*',
                'client/scripts/*.*'
            ],
            options: {
                verbose: true
            }
        }

Can you try to run:

grunt retire:js

and then

grunt retire:node

And see which one produces the crash?

@eoftedal The error does not happen when I run grunt retire alone. It only happens when I run other grunt tasks, i.E. when starting the server and minifying CSS stuff like I mentioned above.

It is weird, indeed. When grunt retire is not directly called nor executed, then why does it trigger the crash then?

Maybe it's actually not related to retire at all. A problem here is that tmp.js creates a global exception handler, which is a bit silly. Can you try commenting out the following:

process.addListener('uncaughtException', function _uncaughtExceptionThrown( err ) {
   _uncaughtException = true;
   _garbageCollector();
   throw err;
});

in node-modules/tmp/lib/tmp.js and see what happens ?

I just removed the tmp-module, and replaced it with os.tmpdir()

@binarykitchen Can you please try the latest version 0.1.21, and see what happens?

@eoftedal Great. So far with v0.1.21 it did not crash anymore. Looking good. I think that did the trick. Thanks guys!