Search code examples
node.jsmemory-leakseventemitter

possible EventEmitter memory leak detected


I am getting following warning:

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace: 
    at EventEmitter.<anonymous> (events.js:139:15)
    at EventEmitter.<anonymous> (node.js:385:29)
    at Server.<anonymous> (server.js:20:17)
    at Server.emit (events.js:70:17)
    at HTTPParser.onIncoming (http.js:1514:12)
    at HTTPParser.onHeadersComplete (http.js:102:31)
    at Socket.ondata (http.js:1410:22)
    at TCP.onread (net.js:354:27)

I wrote code like this in server.js:

http.createServer(
    function (req, res) { ... }).listen(3013);

How to fix this ?


Solution

  • This is explained in the node eventEmitter documentation

    What version of Node is this? What other code do you have? That isn't normal behavior.

    In short, its: process.setMaxListeners(0);

    Also see: node.js - request - How to “emitter.setMaxListeners()”?