question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

QueryIterator should use setImmediate for callbacks to avoid max call stack

See original GitHub issue

QueryIterator’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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ctstonecommented, Jun 20, 2017

@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!

1reaction
mehdijazayeri3000commented, Jun 21, 2017

@ctstone Thank you so much. We will fix this as soon as possible.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found