Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Weird 'Maximum call stack size exceeded' errors @ 3.8.6 #1920

Closed
d-oliveros opened this Issue · 26 comments
@d-oliveros

Hello. I'm getting a 'Maximum call stack size exceeded' error when upgrading from 3.8.5 to 3.8.6. Reverting the version back to 3.8.5 seems to fix the issue.

I tried to trace the error back with no luck. If I try to run node with --stack-size=10000, I get a "Segmentation fault" error. The only solution I could find was revert the version to 3.8.5.

Is anyone else having issues with this?

The affected query looks like this:

var query = { _id: '52f2f10153a87ced0e04f6c6', community: { '$in': [ 1 ] } }

var update = { '$push':
{ comments:
{ user: 52f2ee3353a87ced0e04f6c5,
body: 'asdqw',
comments: [],
_id: 52f44fc8f5d436332ae8293d,
created: Thu Feb 06 2014 22:15:20 GMT-0500 (EST),
counts: { appreciations: 0, comments: 0 } } },
'$inc': { 'counts.comments': 1, karma: 90 } }

var fetch = { community: true,
user: true,
userName: true,
path: true,
title: true }

Post
.findOneAndUpdate(query, update, {select: fetch})
.exec(function(err, post){ ... })

@japrescott

is there an update on this issue? uncatched error @
/home/jeremy/Programming/mysr.ch/node_modules/mongoose/node_modules/mquery/lib/utils.js:26
if (/ObjectI[dD]$/.test(obj.constructor.name)) {
^
RangeError: Maximum call stack size exceeded
worker 28633 died (8). restarting...

node 0.10.25

@japrescott japrescott referenced this issue in aheckmann/mquery
Closed

maximum call stack size exceeded #35

@UnnatiThakker

Even i am also facing the same problem. But weird is the same code runs on different machine. So i am wondering if this is problem of version mismatch or some thing else

@aheckmann
Owner

I am unable to reproduce. Please post your schema and code I can run to trigger the error. Thanks

@UnnatiThakker

I resolved it by reverting mongoose module to 3.8.5. Thanks.

@tewk

The problem for me seems to be in mquery.

/home/tewk/srcs/therapy-ally/node_modules/mongoose/node_modules/mquery/lib/utils.js:26
if (/ObjectI[dD]$/.test(obj.constructor.name)) {
^
RangeError: Maximum call stack size exceeded

I added console.log(obj.constructor.name) above line 26 and got the following loop
NativeConnection
Mongoose
NativeConnection
Mongoose
NativeConnection
Mongoose
NativeConnection
Mongoose
NativeConnection
Mongoose
NativeConnection
Mongoose
NativeConnection
Mongoose
NativeConnection
Mongoose
NativeConnection
Mongoose
NativeConnection
Mongoose
NativeConnection
Mongoose
NativeConnection
Mongoose
NativeConnection
Mongoose
NativeConnection
Mongoose
NativeConnection
Mongoose
NativeConnection
Mongoose

@japrescott

@aheckmann I would like to provide you with code but since the stack is swallowed, I have no clue where this error arises. Is there a way to catch such an error and get the trace without putting everything into a try catch or using the unstable nodejs.domain approach?

@aheckmann
Owner

There must be a way to log requests or something to help you track down what triggered it. Once you can reproduce, you might use node-inspector. As long as you can narrow it down to some schemas and code I can run to reproduce I can take it from there.

@seyDoggy

@aheckmann I'm having this issue as well. I was able to trace it as far back as this commit in mquery/lib/utils.js and seems to concern the utlis.clone() function from that point forward. I tried chasing the rabbit farther but I was afraid I'd never come up for air.

@lefnire lefnire referenced this issue from a commit in HabitRPG/habitrpg
@lefnire lefnire fix(mongo): tmp fix to #3607 until 8d31376
@jamesdbell

I am getting this error as well.

@vkarpov15 vkarpov15 added the bug? label
@eiriklv

I am getting this error as well, when performing a "findByIdAndUpdate" query. Was working before updating to 3.8.6.

Edit: After downgrading to 3.8.5 everything works as expected again.

@portokallidis

I am getting this error too, when doing a find({}).select('').exec on v3.8.12 , i will downgrade to 3.8.5 and see again
EDIT: I found that the $not operator has the issue , i used the $ne for each parameter instead

@thorning

I got this error as well, I will downgrade to 2.8.5 and see if it solves it.

@vkarpov15
Owner

Heya @jamesdbell @eiriklv @portokallidis @thorning , can y'all provide some example code that duplicates this? Would go a long way to helping debug this.

@eiriklv

@vkarpov15 it seems to be caused by nested schemas for my part. Will try to make a condensed example that reproduces the error as soon as i have time (the codebase it originates from is quite large..)

@portokallidis

Also nested schema with the $not operator like this :
OtherModel.findOne({_id:1234}).exec(function(err,data){
if(err) return show(err);
model.find({ unicorn: { $not : data.butterfly } }).select('name otherproperty').exec(function(err,data){
if(err) return show(err);
do_stuff();
});
});
*Also the select method doesn't work as it say , in this example it selected more than these 2

@xizhao

I found this with a findAndModify as well.

@vkarpov15
Owner

@xizhao code example would really help, I haven't been able to reproduce this :(

@rwilcox

Same thing here: was on 3.8.15, getting these issues, then downgraded to 3.8.5 and they are fixed. (I was using findAndModify)

I'll try to create some code examples to help repo this issue.

@vkarpov15
Owner

Please do, no dice on my front being able to repro.

@eiriklv

On my part it depends on what is already in the collection/db, which is why it might be good to supply a dump of your current collection/db when trying to reproduce the error. Will do so myself as well when i have the time

@lefnire

Indeed, I just tried upgrading from 3.8.5 => 3.8.15 (I tried 3.8.6 way back when), and same issue. The full error:

Error message
RangeError: Maximum call stack size exceeded

Stack trace
No listeners detected, throwing. Consider adding an error listener to your connection.
RangeError: Maximum call stack size exceeded
at Array.MongooseArray (/app/node_modules/mongoose/lib/types/array.js:29:12)
at SchemaArray.cast (/app/node_modules/mongoose/lib/schema/array.js:139:15)
at /app/node_modules/mongoose/lib/document.js:288:29
at EmbeddedDocument.Document.$__try (/app/node_modules/mongoose/lib/document.js:760:8)
at init (/app/node_modules/mongoose/lib/document.js:287:16)
at EmbeddedDocument.Document.init (/app/node_modules/mongoose/lib/document.js:246:3)
at DocumentArray.cast (/app/node_modules/mongoose/lib/schema/documentarray.js:140:27)
at /app/node_modules/mongoose/lib/document.js:288:29
at model.Document.$__try (/app/node_modules/mongoose/lib/document.js:760:8)
at init (/app/node_modules/mongoose/lib/document.js:287:16)
at model.Document.init (/app/node_modules/mongoose/lib/document.js:246:3)
at completeOne (/app/node_modules/mongoose/lib/query.js:1392:10)
at Object.cb (/app/node_modules/mongoose/lib/query.js:1151:11)
at Object.<anonymous> (/app/node_modules/mongoose/node_modules/mquery/lib/utils.js:137:16)
at Object._onImmediate (/app/node_modules/newrelic/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31)
at processImmediate [as _immediateCallback] (timers.js:345:15)

It'll be quite difficult for me to isolate it, as our code does some pretty ugly stuff. Anyway, it starts here (or at least in that surrounding function). That's user.save() - I don't think it's triggering by User.findAnd.. or User.findOne or any of that; we do have those ops in our code, but this stack trace is starting after that had already been performed. Our model is here, a very likely candidate is the arrays of embedded documents (see habits, dailys, todos, rewards). Could be that a user has many array elements, and that updating at an array location is pretty heavy on Mongoose - I know Mongoose has that ol' _v workaround for array-edit race-conditions. I'll check back if I can pin-point / think of anything else

[Edit] Also hard for me to isolate as I still can't reproduce myself, try as I may. I'm seeing the error on prod via NewRelic by other users, ~1error/minute @1k RPM - I'll see about adding some extra logging on those error throws

@soichih

I am having the same problem, and here is a mocha test case to recreate this problem.

crash
✓ should crash
Mongoose: parents.insert({ __v: 0, children: [ { name: 'child name', _id: ObjectId("540220ac87f459ac3d9a778e") } ], _id: ObjectId("540220ac87f459ac3d9a778d") }) {}
1) should crash

1) crash should crash:
Uncaught Maximum call stack size exceeded

var mongoose = require('mongoose');

var parentSchema = new mongoose.Schema({
    children: [ new mongoose.Schema({
        name: String,
    })]
});

var Parent = mongoose.model('Parent', parentSchema);

describe('crash', function() {
    it('should crash', function(done) {
        var parent = new Parent();
        parent.children.push({name: 'child name'});
        parent.save(function(err, it) {
            parent.children.push({name: 'another child'});
            Parent.findByIdAndUpdate(it._id, {$set: {children: parent.children}}, function(err, affected) {
                console.dir(affected);
            });
        });

        done();
    });
@lefnire lefnire referenced this issue in HabitRPG/habitrpg
Closed

Error starting server #3961

@vkarpov15 vkarpov15 added this to the 3.8.17 milestone
@vkarpov15 vkarpov15 referenced this issue from a commit
@vkarpov15 vkarpov15 Test case for #1920 e9231f2
@vkarpov15 vkarpov15 closed this issue from a commit
@vkarpov15 vkarpov15 Fix #1920 439e486
@vkarpov15 vkarpov15 closed this in 439e486
@vkarpov15
Owner

This fix will be in 3.8.17 and 3.9.3. The issue was that mquery was trying to update the whole mongoose object, e.g. __parent and all, instead of using the underlying POJO. Should work fine now. @soichih thanks for reproducing this.

@memelet

I am seeing this now with 4.0.2. I am updating just a part of the document. Will post more if learn anything.

@vkarpov15
Owner

Please do @memelet. The test isn't failing so I doubt it's the exact same issue...

@memelet

The problem was invoking findOneAndUpdate(.., {upsert: true, new: true})

where update document contained attributes with undefined values.

eg,

{
  tenant: "tenantA",
  plants: undefined
}

When took care to remove undefined keys from the document the upsert works correctly.

Specifying undefined certainly should not be valid, but error could be handled better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.