I've found that sockets are not fully destroyed in socket io server side when manually disconnecting them. I've found this topic on github useful. While I'm looking for some variable-links that prevent GC from cleaning sockets, I'm asking a question here.
If anyone here encountered the same problem, this would be much help.
the code that does not work:
socket.on('disconnect', function(){
socket.removeAllListeners();
});
///...................
socket.disconnect();
Workaround that, however, uses restricted library fields:
delete io.sockets[url];
io.j = [];
Socket.IO requires a lot of memory which is a potential problem. SockJS does not scale well at all and does not manage the same level of concurrency as the other two.
Key Differences between WebSocket and socket.ioIt provides the Connection over TCP, while Socket.io is a library to abstract the WebSocket connections. WebSocket doesn't have fallback options, while Socket.io supports fallback. WebSocket is the technology, while Socket.io is a library for WebSockets.
As we saw in the performance section of this article, a Socket.IO server can sustain 10,000 concurrent connections.
Closures, timers, and event handlers can often create memory leaks in Node. js applications. Let's look at a piece of code from the Meteor team explaining a closure that leads to a memory leak. It leads to a memory leak as the longStr variable is never collected and keeps growing in memory.
actually, this is working as intended, when you disconnect a socket you simply state you're not expecting to receive any more data from that socket right now, to actually destroy the socket you basically do the delete socket
action. Use this on the disconnect event, ie:
socket.on('disconnect', function(){
delete socket;
})
you can also do this on the io.sockets.sockets Object on an external function:
function deleteSocket(socketID){
delete io.sockets.sockets[socketID];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With