Skip to content
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

Maximum call stack size exceeded #10449

Closed
simllll opened this issue Jul 13, 2021 · 19 comments
Closed

Maximum call stack size exceeded #10449

simllll opened this issue Jul 13, 2021 · 19 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@simllll
Copy link
Contributor

simllll commented Jul 13, 2021

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

@IslandRhythms
Copy link
Collaborator

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:

Object.values would return the values in the key value pair so instead of returning {a:1} it will just return 1.

Please provide a script that demonstrates these issues you have

@IslandRhythms IslandRhythms added the needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue label Jul 13, 2021
@CraigglesO
Copy link

I can comment on this. The cursor doesn't clean up after itself, so if you have millions of data points, it will eventually use up too much:

Screen Shot 2021-07-13 at 12 26 15

Here is a simplified version of my script:

const fs = require('fs')
const mongoose = require('mongoose')
const log = require('single-line-log').stdout

const PlacePointModel = require('./schema/PlacePoint.js').PlacePointModel

let total = 0

async function BUILD () {
  await mongoose.connect('mongodb://127.0.0.1:27017/data', {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    useFindAndModify: false,
    useCreateIndex: true
  })

  const db = mongoose.connection

  const pointCursor = PlacePointModel.find().populate('relations').cursor()

  for (let point = await pointCursor.next(); point != null; point = await pointCursor.next()) {
    log(++total)
    // pull
    const { ... } = point
    // manipulate

    ...

    // store
    fs.appendFileSync('./data.json', JSON.stringify(feature) + '\n')
  }

  db.close()
}

BUILD()

version of node: 12.22.3
mongoose: 5.13.2

@simllll
Copy link
Contributor Author

simllll commented Jul 14, 2021

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:

Object.values would return the values in the key value pair so instead of returning {a:1} it will just return 1.

Please provide a script that demonstrates these issues you have

Sorry, I meant Object.entries, but the main culprit here is that it reported values/keys/content which is not part of the original object.

Simplified version of a scirpt that produces this errornous output:

import 'reflect-metadata';
import { DBUserModel } from '@hokify/user-data';
import { DBMailBounceModel } from '@hokify/messaging-servicefeedback';
import { ObjectId } from 'mongodb';
import { MongooseConnection } from '../src';

(async () => {
	await MongooseConnection.connect();

        // fetch a user object 
	const selUser = await DBUserModel.findOne({
		_id: new ObjectId('60e61c0dd8c15500190e031b')
	}).exec();

        // fetc mail bounces
	await DBMailBounceModel.findOne({ email: selUser.general.email })
		.exec()
		.then(bounce => {
			selUser.mailBounce = bounce;
		});

	console.log('selUser.mailBounce', selUser.mailBounce);

	console.log('selUser.privacy', selUser.privacy);
	console.log('JSON.stringify(selUser.privacy)', JSON.stringify(selUser.privacy));
	console.log('Object.keys(selUser.privacy)', Object.keys(selUser.privacy));
	console.log(
		'Object.entries(selUser.privacy)',
		Object.entries(selUser.privacy).map(
			([key, _value]) => `privacy[${key}]` + `: ${selUser.privacy[key] ? 'Exists' : ' FAIL'}`
		)
	);
})();

and the output of this scirpt:

selUser.mailBounce {
  amount: 1,
  _id: 60ebe31dd4b4c9cf128712cb,
  email: 'ewald_dresbach@yahoo.it',
  __v: 0,
  createdAt: 2021-07-12T06:37:17.224Z,
  lastError: 'Permanent, General / failed:smtp; 552 1 Requested mail action aborted, mailbox not found',
  updatedAt: 2021-07-12T06:37:17.224Z
}
selUser.privacy { user_register: 2021-07-07T21:26:37.934Z }
JSON.stringify(selUser.privacy) {"user_register":"2021-07-07T21:26:37.934Z"}
Object.keys(selUser.privacy) [
  '$init',
  'mailBounce',
  'user_register',
  'user_application',
  'user_active_sourcing',
  'company_register',
  'company_posting',
  'company_application',
  'company_club',
  'company_digital_content'
]
Object.entries(selUser.privacy) [
  'privacy[$init]: Exists',
  'privacy[mailBounce]: Exists',
  'privacy[user_register]: Exists',
  'privacy[user_application]:  FAIL',
  'privacy[user_active_sourcing]:  FAIL',
  'privacy[company_register]:  FAIL',
  'privacy[company_posting]:  FAIL',
  'privacy[company_application]:  FAIL',
  'privacy[company_club]:  FAIL',
  'privacy[company_digital_content]:  FAIL'
]

look at selUser.privacy and JSON.stringify => all good
but look at Object.keys or Object.values => it returns weird other stuff (e.g. it includes mailBoucne?!).
The mongoose model defintion part of the user object for privacy looks like this:

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
	},

there is no such thing as mailBounce.. furthermore if I add .lean() to the user query, all works correctly.

Version checks:

  • mongoose 5.10.19: works (no mailBounce within the selUser.privacy)
  • mongoose 5.11.20: works
  • mongoose 5.12.1: works
  • mongoose 5.12.10: works
  • mongoose 5.12.12: works
  • mongoose 5.12.13: broken
  • mongoose 5.12.15: broken
  • mongoose 5.13.2: broken

so it seems the bug got introduced in 5.12.13.

not quite sure if this is bug is directly related to the e.g. non freeing cursors issues? is this somehow related? @CraigglesO can you verify if the cursor issue also got introduced in 5.12.13?

@IslandRhythms
Copy link
Collaborator

Please include your models @simllll

@IslandRhythms
Copy link
Collaborator

IslandRhythms commented Jul 14, 2021

@CraigglesO Please define what feature is suppose to be along with the {...} = point as well as your model

@simllll
Copy link
Contributor Author

simllll commented Jul 14, 2021

Please include your models @simllll

const userSchema = new Schema({
		general: {
			email: { type: String, lowercase: true, trim: true },
		},
		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
		}
	});

	const DBUserModel = model('UserMongooseBug', userSchema);

	await DBUserModel.create({
		general: {
			email: 'test'
		},
		privacy: {
			user_register: new Date()
		}
	});

	const mailBounceSchema = new Schema(
		{
			email: {
				type: String,
				unique: true,
				required: true,
				dropDups: true
			},
			amount: { type: Number, default: 0 },
			lastError: Schema.Types.Mixed
		},
		{
			timestamps: true
		}
	);

	const DBMailBounceModel = model('MailBounceMongooseBug', mailBounceSchema);

	await DBUserModel.create({
		email: 'test',
		amount: 1,
		lastError: {
			bla: true
		}
	});

@IslandRhythms
Copy link
Collaborator

const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({
	general: {
		email: { type: String, lowercase: true, trim: true },
	},
	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
	}
});

const DBUserModel = mongoose.model('UserMongooseBug', userSchema);

const mailBounceSchema = new mongoose.Schema(
	{
		email: {
			type: String,
			unique: true,
			required: true,
			dropDups: true
		},
		amount: { type: Number, default: 0 },
		lastError: mongoose.Schema.Types.Mixed
	},
	{
		timestamps: true
	}
);

const DBMailBounceModel = mongoose.model('MailBounceMongooseBug', mailBounceSchema);

(async () => {
	await mongoose.connect('mongodb://localhost:27017/test', { useNewUrlParser: true, useUnifiedTopology: true });
	await mongoose.connection.dropDatabase();
	
	let general = await DBUserModel.create({
		general: {
			email: 'test'
		},
		privacy: {
			user_register: new Date()
		}
	});

	let entry = await DBUserModel.create({
		email: 'test',
		amount: 1,
		lastError: {
			bla: true
		}
	});
        // fetch a user object 
	const selUser = await DBUserModel.findOne({
		_id: general._id
	}).exec();

        // fetc mail bounces
	await DBMailBounceModel.findOne({ email: selUser.general.email })
		.exec()
		.then(bounce => {
			selUser.mailBounce = bounce;
		});

	console.log('selUser.mailBounce', selUser.mailBounce);

	console.log('selUser.privacy', selUser.privacy);
	console.log('JSON.stringify(selUser.privacy)', JSON.stringify(selUser.privacy));
	console.log('Object.keys(selUser.privacy)', Object.keys(selUser.privacy));
	console.log(
		'Object.entries(selUser.privacy)',
		Object.entries(selUser.privacy).map(
			([key, _value]) => `privacy[${key}]` + `: ${selUser.privacy[key] ? 'Exists' : ' FAIL'}`
		)
	);
})();

@IslandRhythms IslandRhythms added can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels Jul 15, 2021
@vkarpov15 vkarpov15 added this to the 5.13.4 milestone Jul 19, 2021
@simllll
Copy link
Contributor Author

simllll commented Jul 20, 2021

Is this intended that you have added the can't reproduce label @IslandRhythms ? If i run your script with mongoose ^5.13.3:

JSON.stringify(selUser.privacy) {"user_register":"2021-07-20T10:24:27.938Z"}
Object.keys(selUser.privacy) [
  '$init',
  'mailBounce',
  'user_register',
  'user_application',
  'user_active_sourcing',
  'company_register',
  'company_posting',
  'company_application',
  'company_club',
  'company_digital_content'
]
Object.entries(selUser.privacy) [
  'privacy[$init]: Exists',
  'privacy[mailBounce]:  FAIL',
  'privacy[user_register]: Exists',
  'privacy[user_application]:  FAIL',
  'privacy[user_active_sourcing]:  FAIL',
  'privacy[company_register]:  FAIL',
  'privacy[company_posting]:  FAIL',
  'privacy[company_application]:  FAIL',
  'privacy[company_club]:  FAIL',
  'privacy[company_digital_content]:  FAIL'
]

I run with ts-node test.ts, mailBounce popps up inside privacy?
node v16.4.0
mongo v4.4.1 (via mongos)

@IslandRhythms
Copy link
Collaborator

My bad, missed the version number

@IslandRhythms IslandRhythms added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. labels Jul 20, 2021
@IslandRhythms
Copy link
Collaborator

So actually looking at it, the mailbounce key does exist but it is null

@IslandRhythms
Copy link
Collaborator

selUser.mailBounce null
selUser.privacy { user_register: 2021-07-20T17:17:25.403Z }
JSON.stringify(selUser.privacy) {"user_register":"2021-07-20T17:17:25.403Z"}
Object.keys(selUser.privacy) [
  '$init',
  'mailBounce',
  'user_register',
  'user_application',
  'user_active_sourcing',
  'company_register',
  'company_posting',
  'company_application',
  'company_club',
  'company_digital_content'
]
Object.entries(selUser.privacy) [
  'privacy[$init]: Exists',
  'privacy[mailBounce]:  FAIL',
  'privacy[user_register]: Exists',
  'privacy[user_application]:  FAIL',
  'privacy[user_active_sourcing]:  FAIL',
  'privacy[company_register]:  FAIL',
  'privacy[company_posting]:  FAIL',
  'privacy[company_application]:  FAIL',
  'privacy[company_club]:  FAIL',
  'privacy[company_digital_content]:  FAIL'
]

@IslandRhythms
Copy link
Collaborator

The fact that our outputs don't line up usually means there is something wrong on your end.

@IslandRhythms
Copy link
Collaborator

this is selUser {
  general: { email: 'test' },
  privacy: { user_register: 2021-07-20T17:22:20.694Z },
  _id: 60f7064c2921a2451c6d2a23,
  __v: 0
}

@simllll
Copy link
Contributor Author

simllll commented Jul 20, 2021

Exactly, but this is wrong ;-) mailbounce should exists on "selUser", but not under privacy. it is set to the "selUser.mailBoucne" not to "selUser.privacy.mailbounce"
look at objects.keys of selUser.privacy or object.entires of seluser.privacy.. it both shows "mailBounce" (which is not part of "privacy" in any way). If you output it via json.stringify, output is fine.

@IslandRhythms IslandRhythms added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Jul 20, 2021
vkarpov15 added a commit that referenced this issue Jul 28, 2021
@vkarpov15
Copy link
Collaborator

@simllll are you setting a batchSize on your cursors? Your stack trace makes it look like there's a huge batchSize.

Thanks for pointing out the privacy.mailBounce issue, we fixed that in 62b7b9c

@simllll
Copy link
Contributor Author

simllll commented Jul 28, 2021

Yeah, right.. the script that breaks has a batchSize set to 150000. Do you think setting it smaller would solve this issue?

@vkarpov15
Copy link
Collaborator

Yep I think the call stack size exceeded error is due to #9366, which made populate work with batchSize rather than populating one at a time. Specifically, it looks like we need to make sure to clear the call stack here to avoid putting 150k calls on the stack.

I think a better option would be to cap the batch size we use for populate() to 1000 or so. Populating 150k documents at a time would likely not work very well.

@simllll
Copy link
Contributor Author

simllll commented Jul 28, 2021

Intersesting, but in this case I'm not populating anything. Only going through the documents as they are (I only can't use lean because I need some information about the model), also in this case we are talking about very small documents where a high batchSize actually has a very good performance impact.

That said, I'm not 100% sure which query is causing this, but in general we are not using populate (there where only some queries left that used mongoose's populate, that we changed in the meantime too ..), as we have our own implementatoin / cache layer to do population,.. which makes my guess stronger that this is not directly related to this 3rd issue. But it's the cause of the 2nd one pretty sure :)

@vkarpov15 vkarpov15 reopened this Jul 28, 2021
@vkarpov15 vkarpov15 modified the milestones: 5.13.4, 5.13.5, 5.13.6 Jul 28, 2021
@vkarpov15
Copy link
Collaborator

@simllll in v5.13.6 we'll clear the stack every 1000 docs, so this stack overflow shouldn't happen anymore. Let me know if this issue persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

4 participants