You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm attempting to set up a express 3 server that creates and removes websocket servers regularly (ie different routes, not just not client sessions) and I've noticed that when a websocket server is recreated at a URL that was previously used by another websocket (that has since been closed), that previous websocket's events still seem to fire.
Steps to reproduce:
Create a websocket server on express 3
Close the websocket server
Create a second websocket server on the same server at the same url
connection events will now be thrown by both the old and new web socket servers whenever a client connects
I console.logged my server after the first websocket server was started and after the second and found that in it's _events some listeners were being duplicated.
I can also post the listening and error fns as well if this is difficult to reproduce
(I ran wss.options.server._events.upgrade.toString())
function (req, socket, upgradeHead) {
//copy upgradeHead to avoid retention of large slab buffers used in node core
var head = new Buffer(upgradeHead.length);
upgradeHead.copy(head);
self.handleUpgrade(req, socket, head, function(client) {
self.emit('connection'+req.url, client);
self.emit('connection', client);
});
}
The text was updated successfully, but these errors were encountered:
So this is a memory leak AFAIK but if you need a quick work around you can call wss.removeAllListeners() after calling close to prevent client connect and client disconnect from firing your previous event listeners.
Edit: should say, it's a memory leak but a real minor one. That's not the major issue, the major issue is that things aren't removed as expected
I'm attempting to set up a express 3 server that creates and removes websocket servers regularly (ie different routes, not just not client sessions) and I've noticed that when a websocket server is recreated at a URL that was previously used by another websocket (that has since been closed), that previous websocket's events still seem to fire.
Steps to reproduce:
I console.logged my server after the first websocket server was started and after the second and found that in it's _events some listeners were being duplicated.
After the first ws is opened:
After the first ws is closed and the second is opened:
This is the function being duplicated in upgrade:
I can also post the listening and error fns as well if this is difficult to reproduce
(I ran
wss.options.server._events.upgrade.toString()
)The text was updated successfully, but these errors were encountered: