Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server upgrade and error listeners not being removed on close #241

Closed
D1plo1d opened this issue Sep 14, 2013 · 2 comments
Closed

Server upgrade and error listeners not being removed on close #241

D1plo1d opened this issue Sep 14, 2013 · 2 comments

Comments

@D1plo1d
Copy link

D1plo1d commented Sep 14, 2013

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:

  1. Create a websocket server on express 3
  2. Close the websocket server
  3. Create a second websocket server on the same server at the same url
  4. 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.

After the first ws is opened:

listening: { [Function: g] listener: [Function] },
error: [Function],
upgrade: [Function]

After the first ws is closed and the second is opened:

listening: [ [Object], [Object] ],
error: [ [Function], [Function] ],
upgrade: [ [Function], [Function]

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())

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);
      });
}
@D1plo1d
Copy link
Author

D1plo1d commented Sep 14, 2013

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

@lpinca
Copy link
Member

lpinca commented Nov 14, 2016

Closing this as I think this issue has been "fixed" by #885. Please comment or reopen if needed.

@lpinca lpinca closed this as completed Nov 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants