NPM Mongo: RangeError: Maximum call stack size exceeded

Hi everyone,

For quite some time now we are riddled with this error, resulting in complete restart of our meteor instances (docker containers).
We are having a very hard time trying to find the root of the problem.

Can anyone help what sometimes can lead to this error?

part of the stack:

RangeError: Maximum call stack size exceeded
at Cursor._initializeCursor (/built_app/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/cursor.js:186:11)
at Cursor._initializeCursor (/built_app/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/cursor.js:541:7)
at executeOperation (/built_app/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/operations/execute_operation.js:34:10)
at maybePromise (/built_app/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/utils.js:692:3)

I hope someone can help! :slight_smile:

Thanks a bunch in advance, best
Patrick

1 Like

Most of the times this is caused by a bug/ bad code. An example from my imagination… mapping over an array with a function that adds elements to that array, in which case a ‘for’ loop should be used instead since the number of elements is being initialized before the loop starts.

I see the cursor is involved here so perhaps it has something to do with mapping over your cursor server side.
E.g.

Collection.find({...}).forEach(...) // or
Collection.find({...}).map(...)

With the monitoring tools from Monti perhaps you can see the last method / publication called before the server crash if the server log presents no hints.

Running your app in production locally might also help you trigger this situation.