-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
JavaScript driver - ArrayResult.next is kind of broken #1578
Comments
The second part of the bug should definitely be fixed (for cursors and arrays). Could you explain what the first bug is more precisely? If there are no more elements, does |
When we call So we never send back an RqlDriverError with a "No more rows" error. |
Working on this one. |
Branch michel_1578_maximum_call_stack |
Review 997 |
I believe a lot of people expect this code to work (See http://stackoverflow.com/questions/18119387/iterating-over-a-mongodb-cursor-serially-waiting-for-callbacks-before-moving-to/18119789#18119789 or https://github.com/rethinkdb/rethinkdb/blob/next/drivers/javascript/cursor.coffee#L21)
It throws with
There are one and a half bugs here.
The first one is that ArrayResult.next doesn't check if there is an element before executing the callback (line 139), so it keeps calling itself with
undefined
as a result.The second one is that if the array has more than 3255 elements, we are still going to get a Maximum call stack (node v0.10.20)
While it's technically the user's fault, I think it would be better for us to provide a better implementation of
next
.I tried a quick fix withsetImmediate
and it seems to work fine in Node.setImmediate
is not defined in some browsers (including Chrome), but asetTimeout
should also do the trick.I'm not sure, but I think we should also use
setImmediate
with a normal cursor too. We may hit the same bug when #1543 will be released (or if the user somehow has 4 nested calls in each callback).The text was updated successfully, but these errors were encountered: