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

fix "RangeError: Maximum call stack size exceeded" #1514

Merged
merged 2 commits into from Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/internal/eachOfLimit.js
Expand Up @@ -15,6 +15,7 @@ export default function _eachOfLimit(limit) {
var nextElem = iterator(obj);
var done = false;
var running = 0;
var looping = false;

function iterateeCallback(err, value) {
running -= 1;
Expand All @@ -26,12 +27,13 @@ export default function _eachOfLimit(limit) {
done = true;
return callback(null);
}
else {
else if (!looping) {
replenish();
}
}

function replenish () {
looping = true;
while (running < limit && !done) {
var elem = nextElem();
if (elem === null) {
Expand All @@ -44,6 +46,7 @@ export default function _eachOfLimit(limit) {
running += 1;
iteratee(elem.value, elem.key, onlyOnce(iterateeCallback));
}
looping = false;
}

replenish();
Expand Down
12 changes: 12 additions & 0 deletions mocha_test/eachOf.js
Expand Up @@ -274,6 +274,18 @@ describe("eachOf", function() {
setTimeout(done, 25);
});

it('forEachOfLimit 1024 * 1024 synchronous call', function(done) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is minor, but we already have a forEachOfLimit synchronous test. Could you rename this to something like forEachOfLimit no stackoverflow or forEachOfLimit no call stack size exceed error just to differentiate between the two?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a similar test for forEachOf and forEachOfSeries to make sure the behaviour is consistent?

var count = 0;
async.forEachOfLimit(_.range(1024 * 1024), Infinity, function(x, i, callback){
count++;
callback();
}, function(err){
if (err) throw err;
expect(count).to.equal(1024 * 1024);
});
setTimeout(done, 25);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you call done inside of the final callback instead?

});

it('forEachOfLimit error', function(done) {
var obj = { a: 1, b: 2, c: 3, d: 4, e: 5 };
var call_order = [];
Expand Down