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

async.each with empty MongooseArray never calls final callback #775

Closed
RBLU opened this issue Jun 2, 2015 · 4 comments
Closed

async.each with empty MongooseArray never calls final callback #775

RBLU opened this issue Jun 2, 2015 · 4 comments
Labels

Comments

@RBLU
Copy link
Contributor

RBLU commented Jun 2, 2015

We just tried to update async, mongoose and io.js and noticed a problem with async.forEach hanging when we pass a Mongoose Array of length 0. The following code leads to the problems:

lib/async.js:224

    var size = object.length || _keys(object).length;

the object.length is 0 because we have an empty Array, and 0 evaluates to falsy, but then mongoose attaches properties to the Array Object, so _keys(object).length returns 33, so size ends up being 33.

but then on iteration in _each the function isArrayLike returns true so it uses _arrayEach to iterate, but there are no entries to iterate because object.length is 0, so the final callback is never called, the 33 properties are never iterated.

This seems inconsistent. I think a correct fix would be to use the isArrayLike in both places:

lib/async.js:224

    var size = isArrayLike(object) ? object.length : _keys(object).length;
@aearly aearly added the bug label Jun 2, 2015
@aearly
Copy link
Collaborator

aearly commented Jun 2, 2015

Good catch. A PR with a regression test would be welcome! Otherwise I'll get to this later today.

@RBLU
Copy link
Contributor Author

RBLU commented Jun 2, 2015

ok, will submit PR

@RBLU
Copy link
Contributor Author

RBLU commented Jun 2, 2015

PR see #777

@aearly aearly closed this as completed in 3b4fd64 Jun 2, 2015
@aearly
Copy link
Collaborator

aearly commented Jun 2, 2015

Thanks for your help!

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