Memory leak: Disconnected socket stays in memory
Hello, the following code leaks ca. 100KB (very roughly) of ram each time I press "reload" in the browser to reload the page and reconnect:
var lightnode = require('lightnode');
var http = require('http');
var fileServer = new lightnode.FileServer('/home/jann/gitty/node-assertvanish/');
var server = http.createServer(function(req, res) {
fileServer.receiveRequest(req, res);
});
server.listen(8080, '0.0.0.0');
var io = require('socket.io').listen(server);
process.on('uncaughtException', function (err) {
console.log('Exception: ' + err);
});
io.sockets.on('connection', function (socket) {
socket.on('disconnect', function() {
console.log("client gone");
});
});
Modified version of the code for generating a memory backtrace Debug output of socket.io and a shortened memory backtrace (I filtered everything out that had an indentation level >12 and shortened the lines to 150 characters because gist didn't want to accept a 710K big file and because it's easier to read this way.)
As you can see, the socket is still referenced by the disconnect handler which in turn is referenced by the socket. It's not the reason of the leak. Therefore, what leaks is namespace.sockets.2644789511415902503. The namespace is also referenced by the second socket (which is alive) and the Manager, and because the namespace still has the dead socket in its sockets object, the dead socket stays in memory.
+1
This workaround seems to be working:
socket.on('disconnect', function() {
delete socket.namespace.sockets[socket.id];
});
is this related ???
https://github.com/LearnBoost/socket.io/issues/405
@dymsza I don't think so, I think it's caused by something else.
Ok, i have other question related to mem leak.
in manager.js we have
this.store.subscribe('disconnect', function (id) { self.onDisconnect(id); });
onDisconnect method is clean up method with clean
manager.handshaken , manager.open ,manager.connected ,manager.transports ,manager.closed , manager.rooms.
BUT:
i real cannot find place with call store.publish('disconnect'); i also used nodeJS inspector and put break point in this method but it look like this method is never run.
For me it look like memory leak.
Thanks,
I will be grateful for the quick reply thanks.
Is this issue still existing? What is the fix?