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 with filters #11

Open
mrmlnc opened this issue Jan 26, 2018 · 1 comment
Open

Maximum call stack size exceeded with filters #11

mrmlnc opened this issue Jan 26, 2018 · 1 comment
Labels

Comments

@mrmlnc
Copy link
Collaborator

mrmlnc commented Jan 26, 2018

Hello,

And it's me again :)

We have a small problem. When working with large nested directory, we often apply the filter. For example, built-in filter by patterns:

const re = require('readdir-enhanced');

let files = null;

try {
    files = re.sync('./node_modules', {
        deep: true,
        filter: '**/test-*'
    });
} catch (error) {
    console.log('MEMORY: ' + (process.memoryUsage().heapUsed / 1e6) + ' MB');

    console.dir(error, { colors: true });
}

console.dir(files, { colors: true });

In the example above, I call the reading of the directory that contains 20320 entries:

$ npm i jest ava babel-core standard eslint typescript tslint monaco xterm readdir-enhanced

After running the script we get the following:

MEMORY: 9.37484 MB

node_modules/readdir-enhanced/lib/call.js:51
      throw err;
      ^

RangeError: Maximum call stack size exceeded
    at Object.fs.lstatSync (fs.js:839:18)
    at exports.lstat (node_modules/readdir-enhanced/lib/sync/fs.js:58:20)
    at Object.safeCall [as safe] (node_modules/readdir-enhanced/lib/call.js:24:8)
    at stat (node_modules/readdir-enhanced/lib/stat.js:19:8)
    at DirectoryReader.processItem (node_modules/readdir-enhanced/lib/directory-reader.js:171:5)
    at node_modules/readdir-enhanced/lib/sync/for-each.js:14:5
    at Array.forEach (native)
    at Object.syncForEach [as forEach] (node_modules/readdir-enhanced/lib/sync/for-each.js:13:9)
    at node_modules/readdir-enhanced/lib/directory-reader.js:80:16
    at onceWrapper (node_modules/readdir-enhanced/lib/call.js:45:17)

If I remove any filter (pattern, function), everything works fine.

@mrmlnc
Copy link
Collaborator Author

mrmlnc commented Jan 31, 2018

I don't know how to fix this problem, except switch to use iteration solution instead of recursive solution.

Temporary, I switch to monkey_fix branch in my package.

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

No branches or pull requests

2 participants