QueryIterator should use setImmediate for callbacks to avoid max call stack
See original GitHub issueQueryIterator’s _toArrayImplementation is a recursive/looping async implementation that calls its callback synchronously. This can lead to RangeError: Maximum call stack size exceeded
for large result sets.
See more: http://stackoverflow.com/questions/20936486/node-js-maximum-call-stack-size-exceeded
The fix is to wrap the callback() in setImmediate or process.nextTick: http://stackoverflow.com/questions/15349733/setimmediate-vs-nexttick
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top Results From Across the Web
QueryIterator should use setImmediate for callbacks to avoid ...
QueryIterator's _toArrayImplementation is a recursive/looping async implementation that calls its callback synchronously.
Read more >Node.js - Maximum call stack size exceeded
This can be a problem if you wish to iterate over an array or list and perform an async operation on each (e.g....
Read more >The Call Stack is Not an Infinite Resource — How to Avoid a ...
The function execute by way of setImmediate aren't scheduled like with setTimeout. Instead, it executes immediately after all Input/Output ...
Read more >JavaScript RangeError: Maximum Call Stack Size Exceeded
In case this error occurs due to an excessive number of function calls or variables, these should be reduced as much as possible....
Read more >Maximum call stack size exceeded-node.js - appsloveworld
The above scenario will cause infamous RangeError: Maximum call stack size exceeded error because the function keeps calling itself so many times that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mehdijazayeri3000, @moderakh, please see repro at https://github.com/ctstone/repro-documentdb-176
The key, I think, is the large maxItemCount, (5000) combined with large-ish documents. I added some logging to
defaultQueryExecutionContext.fetchMore
to see how many documents are coming down over the wire, and it fails when the number reaches around 4500 in one response. My average document size is around 2200 bytes.In general, async methods should never be called recursively without using one of setImmediate, process.nextTick, or setTimeout. See the StackOverflow link in the OP for more details.
Thanks!
@ctstone Thank you so much. We will fix this as soon as possible.