nodejs setMaxListeners to avoid memory leak detection
node.js, socket.io
Solution
You are attaching listeners to io.sockets (io.sockets.on(...)). And you should apply setMaxListeners to the same object (to EventEmmiter). So try:
io.sockets.setMaxListeners(0);
Problem
I read some other questions and posts, but I couldn't find where to apply .setMaxListeners(0). I'm using a simple websocket-server which comes up with the errer: ``` (node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit. Trace at Socket.EventEmitter.addListener (events.js:160:15) at Socket.Readable.on (_stream_readable.js:689:33) at XHRPolling.Transport.setHandlers (D:\nodeJS\host\node_modules\socket.io\lib\transport.js:116:15) at XHRPolling.HTTPPolling.setHandlers (D:\nodeJS\host\node_modules\socket.io\lib\transports\http-polling.js:53:39) at XHRPolling.Transport.handleRequest (D:\nodeJS\host\node_modules\socket.io\lib\transport.js:70:10) at XHRPolling.HTTPTransport.handleRequest (D:\nodeJS\host\node_modules\socket.io\lib\transports\http.js:84:39) at XHRPolling.HTTPPolling.handleRequest (D:\nodeJS\host\node_modules\socket.io\lib\transports\http-polling.js:73:41) at XHRPolling.Transport (D:\nodeJS\host\node_modules\socket.io\lib\transport.js:31:8) at XHRPolling.HTTPTransport (D:\nodeJS\host\node_modules\socket.io\lib\transports\http.js:29:13) at XHRPolling.HTTPPolling (D:\nodeJS\host\node_modules\socket.io\lib\transports\http-polling.js:27:17) ``` I'm instantiating the router this way: ``` var app = require('http').createServer(handler) , io = require('socket.io').listen(app, { log: false }) , fs = require('fs'); app.listen(8070); ``` Then I'm listening for incomming socket-requests: ``` io.sockets.on('connection', function (socket) { socket.on('createTake', function(data){...} }); ``` Where can I apply the MaxListeners? I already tried this: ``` io.sockets.on(...).setMaxListeners(0); ``` But it doesn't work.