async.each with empty MongooseArray never calls final callback
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;
Good catch. A PR with a regression test would be welcome! Otherwise I'll get to this later today.
ok, will submit PR
PR see #777
Thanks for your help!