简体   繁体   中英

“EventEmitter memory leak ” occuring inspite of using latest version of nodejs

After lot of hard trying and googling, I'm still unable to figure out how to tackle this. Need help plz...

Output:

    (node) warning: possible EventEmitter memory leak detected. 51 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at EventEmitter.addListener (events.js:160:15)
    at EventEmitter.once (events.js:179:8)
    at SkinCollection.open (/home/nitin/node_modules/mongoskin/lib/mongoskin/collection.js:108:20)
    at obj.(anonymous function) [as insert] (/home/nitin/node_modules/mongoskin/lib/mongoskin/utils.js:64:10)
    at insertErrorLog (/home/nitin/dev/aayush/errorLog.js:37:18)
    at Server.<anonymous> (/home/nitin/dev/aayush/errorLog.js:69:24)
    at Server.EventEmitter.emit (events.js:98:17)
    at HTTPParser.parser.onIncoming (http.js:2022:12)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:119:23)
    at Socket.socket.ondata (http.js:1912:22)

CODE LINK: link to code

Thnax in advance for help...

It looks like db.collection creates an EventEmitter whenever you call it. Can you should try to cache the collection outside of your request handler:

var logs = db.collection('logs');

var insertErrorLog = function (req, res) {
  var pathname = url.parse(req.url).pathname;
  var ua = req.headers['user-agent'];     // user-agent header from an HTTP request
  var details = parser.setUA(ua).getResult();
  var params = url.parse(req.url,true).query;

  logs.insert({…});

A quick look at the code shows that it should always return the same instance, but I can't see any other reason for your problem:

https://github.com/kissjs/node-mongoskin/blob/master/lib/mongoskin/db.js#L148

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM