Skip to content

Maximum call stack size exceeded #10449

@simllll

Description

@simllll

Do you want to request a feature or report a bug?
bug

What is the current behavior?
there are some other issues out there with maximum call stack size exceeded, but I#m unsure if they are related to this one:

[13.07.2021 11:15.30.785] [ERROR] RangeError: Maximum call stack size exceeded
--
  | 2021-07-13T11:15:30.785+02:00 | at handleCallback (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:34:5)
  | 2021-07-13T11:15:30.785+02:00 | at nextFunction (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:867:5)
  | 2021-07-13T11:15:30.785+02:00 | at Cursor._next (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:202:5)
  | 2021-07-13T11:15:30.785+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:249:14
  | 2021-07-13T11:15:30.785+02:00 | at maybePromise (/app/node_modules/mongoose/node_modules/mongodb/lib/utils.js:692:3)
  | 2021-07-13T11:15:30.785+02:00 | at Cursor.next (/app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:234:12)
  | 2021-07-13T11:15:30.785+02:00 | at Object._onNext (/app/node_modules/mongoose/lib/cursor/QueryCursor.js:422:21)
  | 2021-07-13T11:15:30.785+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/utils.js:704:5
  | 2021-07-13T11:15:30.785+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:252:9
  | 2021-07-13T11:15:30.785+02:00 | at handleCallback (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:32:5)
  | 2021-07-13T11:15:30.785+02:00 | at nextFunction (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:867:5)
  | 2021-07-13T11:15:30.785+02:00 | at Cursor._next (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:202:5)
  | 2021-07-13T11:15:30.785+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:249:14
  | 2021-07-13T11:15:30.785+02:00 | at maybePromise (/app/node_modules/mongoose/node_modules/mongodb/lib/utils.js:692:3)
  | 2021-07-13T11:15:30.785+02:00 | at Cursor.next (/app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:234:12)
  | 2021-07-13T11:15:30.785+02:00 | at Object._onNext (/app/node_modules/mongoose/lib/cursor/QueryCursor.js:422:21)
  | 2021-07-13T11:15:30.785+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/utils.js:704:5
  | 2021-07-13T11:15:30.785+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:252:9
  | 2021-07-13T11:15:30.785+02:00 | at handleCallback (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:32:5)
  | 2021-07-13T11:15:30.785+02:00 | at nextFunction (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:867:5)
  | 2021-07-13T11:15:30.785+02:00 | at Cursor._next (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:202:5)
  | 2021-07-13T11:15:30.785+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:249:14
  | 2021-07-13T11:15:30.785+02:00 | at maybePromise (/app/node_modules/mongoose/node_modules/mongodb/lib/utils.js:692:3)
  | 2021-07-13T11:15:30.785+02:00 | at Cursor.next (/app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:234:12)
  | 2021-07-13T11:15:30.785+02:00 | at Object._onNext (/app/node_modules/mongoose/lib/cursor/QueryCursor.js:422:21)
  | 2021-07-13T11:15:30.785+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/utils.js:704:5
  | 2021-07-13T11:15:30.786+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:252:9
  | 2021-07-13T11:15:30.786+02:00 | at handleCallback (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:32:5)
  | 2021-07-13T11:15:30.786+02:00 | at nextFunction (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:867:5)
  | 2021-07-13T11:15:30.786+02:00 | at Cursor._next (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:202:5)
  | 2021-07-13T11:15:30.786+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:249:14
  | 2021-07-13T11:15:30.786+02:00 | at maybePromise (/app/node_modules/mongoose/node_modules/mongodb/lib/utils.js:692:3)
  | 2021-07-13T11:15:30.786+02:00 | at Cursor.next (/app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:234:12)
  | 2021-07-13T11:15:30.786+02:00 | at Object._onNext (/app/node_modules/mongoose/lib/cursor/QueryCursor.js:422:21)
  | 2021-07-13T11:15:30.786+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/utils.js:704:5
  | 2021-07-13T11:15:30.786+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:252:9
  | 2021-07-13T11:15:30.786+02:00 | at handleCallback (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:32:5)
  | 2021-07-13T11:15:30.786+02:00 | at nextFunction (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:867:5)
  | 2021-07-13T11:15:30.786+02:00 | at Cursor._next (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:202:5)
  | 2021-07-13T11:15:30.786+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:249:14
  | 2021-07-13T11:15:30.786+02:00 | at maybePromise (/app/node_modules/mongoose/node_modules/mongodb/lib/utils.js:692:3)
  | 2021-07-13T11:15:30.786+02:00 | at Cursor.next (/app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:234:12)
  | 2021-07-13T11:15:30.786+02:00 | at Object._onNext (/app/node_modules/mongoose/lib/cursor/QueryCursor.js:422:21)
  | 2021-07-13T11:15:30.786+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/utils.js:704:5
  | 2021-07-13T11:15:30.786+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:252:9
  | 2021-07-13T11:15:30.786+02:00 | at handleCallback (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:32:5)
  | 2021-07-13T11:15:30.786+02:00 | at nextFunction (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:867:5)
  | 2021-07-13T11:15:30.786+02:00 | at Cursor._next (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:202:5)
  | 2021-07-13T11:15:30.786+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:249:14
  | 2021-07-13T11:15:30.786+02:00 | at maybePromise (/app/node_modules/mongoose/node_modules/mongodb/lib/utils.js:692:3)
  | 2021-07-13T11:15:30.786+02:00 | at Cursor.next (/app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:234:12)
  | 2021-07-13T11:15:30.786+02:00 | at Object._onNext (/app/node_modules/mongoose/lib/cursor/QueryCursor.js:422:21)
  | 2021-07-13T11:15:30.786+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/utils.js:704:5
  | 2021-07-13T11:15:30.786+02:00 | at /app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:252:9
  | 2021-07-13T11:15:30.786+02:00 | at handleCallback (/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:32:5)

If the current behavior is a bug, please provide the steps to reproduce.
I cannot really reproduce it, as it seems it only happens from time to time, but it crashes the whole node process after that.
I see following strange behaviours:

  1. JSON.stringify(mongooseModelResult[0].someProperty) returns e.g. { a: 1 }, but Object.values(mongooseModelResult[0].someProperty) returns something complete different? This reminds me of a memory issue in good old c? This issue is gone if I use .lean() for the query... still doesn't seem right.
    The related has this structure:
user.privacy: {
		user_register: Date,
		user_application: Date,
		user_active_sourcing: Date,
		company_register: Date,
		company_posting: Date,
		company_application: Date,
		company_club: Date,
		company_digital_content: Date
	},

with one data point set:

user.privacy: {
user_register: some-Date
}

after the mongoose result, I add some more data to the object, in this case I added to the root object "user.mailBounces = {...}".
when I use Object.values of user.privacy I get also the mailBounces values returned?
2. For some models and queries it seems if I use populate the call stack size exceeded error appears. It only helps to remove populate from these kind of queries. THe strange thing is: it seems to be related with the data of the collecitno, as this is only happening for us on produciton, but not on the test environment?
3. The error above: The main issue with that is that I cannot even say where it is coming from, as the stacktrace doesn't let me debug this. But I guess it has something similar like point 2.

{
	"compilerOptions": {
		// https://node.green/#ES2020
		"module": "commonjs",
		"target": "es2020",
		"lib": ["es2020"],

		// other best practice configs
		"noUncheckedIndexedAccess": true,
		"moduleResolution": "node",
		"strict": true,
		"noImplicitAny": false, 
		"removeComments": false,
		"emitDecoratorMetadata": true,
		"composite": true,
		"experimentalDecorators": true,
		"strictPropertyInitialization": false,
		"resolveJsonModule": true,
		"sourceMap": true,
		"isolatedModules": false,
		"declaration": true,
		"skipLibCheck": true,
		"noImplicitOverride": true
	},
	"files": ["types/lib.shim.d.ts", "types/mongoose.d.ts"],
	"exclude": ["node_modules", "**/__tests__"]
}

I put all these 3 issues into one ticket, as I hardly believe this is all related with virtuals somehow?

What is the expected behavior?
no errors, I just recently upgraded from
"mongoose": "5.10.19",
to
"mongoose": "^5.13.2",
..there were no issues with 5.10.19.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
mongoose: 5.13.12
node: v16.4.0
mongodb: 4.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis issue is a user-facing general improvement that doesn't fix a bug or add a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions