{"action":"created","issue":{"url":"https://api.github.com/repos/websockets/ws/issues/241","repository_url":"https://api.github.com/repos/websockets/ws","labels_url":"https://api.github.com/repos/websockets/ws/issues/241/labels{/name}","comments_url":"https://api.github.com/repos/websockets/ws/issues/241/comments","events_url":"https://api.github.com/repos/websockets/ws/issues/241/events","html_url":"https://github.com/websockets/ws/issues/241","id":19510069,"number":241,"title":"Server upgrade and error listeners not being removed on close","user":{"login":"D1plo1d","id":145184,"avatar_url":"https://avatars.githubusercontent.com/u/145184?v=3","gravatar_id":"","url":"https://api.github.com/users/D1plo1d","html_url":"https://github.com/D1plo1d","followers_url":"https://api.github.com/users/D1plo1d/followers","following_url":"https://api.github.com/users/D1plo1d/following{/other_user}","gists_url":"https://api.github.com/users/D1plo1d/gists{/gist_id}","starred_url":"https://api.github.com/users/D1plo1d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/D1plo1d/subscriptions","organizations_url":"https://api.github.com/users/D1plo1d/orgs","repos_url":"https://api.github.com/users/D1plo1d/repos","events_url":"https://api.github.com/users/D1plo1d/events{/privacy}","received_events_url":"https://api.github.com/users/D1plo1d/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2013-09-14T20:52:15Z","updated_at":"2016-11-14T17:31:29Z","closed_at":"2016-11-14T17:31:29Z","body":"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.\n### Steps to reproduce:\n1. Create a websocket server on express 3\n2. Close the websocket server\n3. Create a second websocket server on the same server at the same url\n4. connection events will now be thrown by both the old and new web socket servers  whenever a client connects\n\nI 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.\n### After the first ws is opened:\n\n```\nlistening: { [Function: g] listener: [Function] },\nerror: [Function],\nupgrade: [Function]\n```\n### After the first ws is closed and the second is opened:\n\n```\nlistening: [ [Object], [Object] ],\nerror: [ [Function], [Function] ],\nupgrade: [ [Function], [Function]\n```\n### This is the function being duplicated in upgrade:\n\nI can also post the listening and error fns as well if this is difficult to reproduce\n\n(I ran `wss.options.server._events.upgrade.toString()`)\n\n```\nfunction (req, socket, upgradeHead) {\n      //copy upgradeHead to avoid retention of large slab buffers used in node core\n      var head = new Buffer(upgradeHead.length);\n      upgradeHead.copy(head);\n\n      self.handleUpgrade(req, socket, head, function(client) {\n        self.emit('connection'+req.url, client);\n        self.emit('connection', client);\n      });\n}\n```\n"},"comment":{"url":"https://api.github.com/repos/websockets/ws/issues/comments/260402651","html_url":"https://github.com/websockets/ws/issues/241#issuecomment-260402651","issue_url":"https://api.github.com/repos/websockets/ws/issues/241","id":260402651,"user":{"login":"lpinca","id":1443911,"avatar_url":"https://avatars.githubusercontent.com/u/1443911?v=3","gravatar_id":"","url":"https://api.github.com/users/lpinca","html_url":"https://github.com/lpinca","followers_url":"https://api.github.com/users/lpinca/followers","following_url":"https://api.github.com/users/lpinca/following{/other_user}","gists_url":"https://api.github.com/users/lpinca/gists{/gist_id}","starred_url":"https://api.github.com/users/lpinca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lpinca/subscriptions","organizations_url":"https://api.github.com/users/lpinca/orgs","repos_url":"https://api.github.com/users/lpinca/repos","events_url":"https://api.github.com/users/lpinca/events{/privacy}","received_events_url":"https://api.github.com/users/lpinca/received_events","type":"User","site_admin":false},"created_at":"2016-11-14T17:31:29Z","updated_at":"2016-11-14T17:31:29Z","body":"Closing this as I think this issue has been \"fixed\" by #885. Please comment or reopen if needed."}}
{"actor":{"display_login":"lpinca"}}