Skip to content


Subversion checkout URL

You can clone with
Download ZIP


RangeError: Maximum call stack size exceeded #688

troyk opened this Issue · 9 comments

4 participants


v2.4.10, node 0.6.7

Before creating this issue I searched the google group and other issues and it looks like this error has popped up before, but here is the sequence of events that cause this error for me.

1) A Buffer field (password) with a setter to hash the password
2) Password is set to the same/similar string

Below is some console output showing this:

> User.findOne({email:/fit/},u); // assign return to u
> u.password = 'rangeerr';
RangeError: Maximum call stack size exceeded
> u.password = 'notrangerr';
> User.findOne({email:/fit/},u); // assign return to u
> u.password = 'rangeerr';

model code:

function hashPass(password) {
  return crypto.createHash('sha1').update(app.secret_token+String(password)).digest();

var User = new Schema({
  email: {type: String, lowercase:true, trim:true, required:true, validate: [stringUtil.isValidEmail, 'Invalid email format'] },
  name: String,
  password: {type: Buffer, set: hashPass, required:true }

I get it also. This happens when you do a find and in the callback try to create another object, you see the exception.

@aheckmann aheckmann closed this in 9409532



With the 2.5.1 version, i get this error again ?
This looks to me coming from the driver rather than in the ORM as such.


@gitfy can you post your code? tests are passing.


I figured out the issue. But the things i am not able exact create a test case that can just narrow the issue.

Here is what is happening :

I am have schema where there is a property of Number type in an embedded obj. I load an instance of this schema from the db and creating another instance where i am assigned this embedded object which has the number property.

During the save, the toObject() doesn't convert Mongoose Number object to a javascript number object. What i saw in the debugger is all the mongoose internals like _atomics etc sent to the driver causing the RangeError.

I wasn't able to narrow this case with a simple scenario. If above scenario provides any clue , i would appreciate if you could fix it. For the moment, during the assignment, i am doing a get(path) to get the value and assigning it to avoid the issue.


I began to get this error too after upgrading to:
mongoose@2.5.3 ./node_modules/mongoose
├── hooks@0.1.9
└── mongodb@0.9.7-3-5

I am trying to generate a test case.


Try the following code. The problem is twitterGroup.sync = null;
If I use twitterGroup.sync = {}; then it works ok.

var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    db = mongoose.connect('mongodb://localhost/mongoose');

db.set('debug', true);

var TwitterGroupSchema = new Schema({
    _id: Buffer,
    sync: {
        started: {type : Date}, 
        status: {type : Number}, 
        cursor: {type : String} 

var TwitterGroup = mongoose.model('TwitterGroup', TwitterGroupSchema);

//Random id 
var id = (new Date()).toString();

var twitterGroup = new TwitterGroup({
     _id: new Buffer(id)
}); {
    if (err) throw err;

    TwitterGroup.findById(id, function(err, twitterGroup) {
        if (err) throw err;

        twitterGroup.sync = null;

        //This one works
        //twitterGroup.sync = {};, twitterGroup) {
            TwitterGroup.findById(id, function(err, twitterGroup) {
                if (err) throw err;

                twitterGroup.sync.started = new Date();
                twitterGroup.sync.status = 0;
                twitterGroup.sync.cursor = '-1';

                    if (err) throw err;

the number bug is fixed in 2.5.4


Great. Thanks.

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.