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

EventEmitter memory leak detected #117

Open
zkrhm opened this issue Aug 21, 2013 · 2 comments
Open

EventEmitter memory leak detected #117

zkrhm opened this issue Aug 21, 2013 · 2 comments

Comments

@zkrhm
Copy link

zkrhm commented Aug 21, 2013

hello, I have problem with mongoskin usage. I use it to move data from postgresql to mongodb. I use loop to move each data like this:

docs.forEach(function(item){
db.docs.insert(item, function(err){

    });

});

mongoskin always printed following warning:

warning: possible EventEmitter memory leak detected. 51 listeners added. Use emitter.setMaxListeners() to increase limit.

seems like 50 maximum listener limit defined inside the the library has been reached. I've try to google it and several sites said that the listener will be queued before connection made to mongodb.

are there more proper-and-not documented way provided to use mongoskin in such condition? are there any way to make node.js ignoring event listener addition?

@naartjie
Copy link

Hi, I am getting the same warning message, with a call to update(). Is this a problem with MongoSkin? Or am I just using it incorrectly:

    var subs = db.collection('subscriptions');
    lines.forEach(function(line) {
        var cond = {foo: bar};
        var update = {$set: {'bar.baz': true}};

        subs.update(cond, update, function(err, up, x) {
            if (err) return console.error(err.toString());
            console.log('updated', up, x);
        });
    });

mongoskin: 0.6.1
node: v0.11.10

@naartjie
Copy link

#39 and #44 were helpful. In my case, the code is part of a standalone script (so the usual initialization code that I use on the server doesn't work here). By the time the update is called, the db connection hasn't been opened yet.

As a workaround, I am using this piece of code to wait until the db is connected, but it is a hack, so I was wondering what is the semantically correct way, using MongoSkin:

var mongo = require('mongoskin'),
    db = mongo.db('mongodb://localhost/db', {safe: true});

// hack to make sure DB is open
db.collection('subscriptions').findOne(function(err) {
  // process a file here, and find what needs to be updated
  db.subscriptions.update({foo: bar}, {$set: {'bar.baz': true}), function(err) {
    if (err) console.error(err.toString());
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants