-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Remove socket listeners on channel disconnect #1375
Remove socket listeners on channel disconnect #1375
Conversation
@@ -26,6 +26,20 @@ function listenToSocketEvents(client) { | |||
client.channel.on('disconnect', client.onDisconnect.bind(client)); | |||
} | |||
|
|||
function stopListeningToSocketEvents(client) { | |||
log.info('Stop listening to socket events'); | |||
client.channel.socketRemoveListener('sendDataStream', client.onSendDataStream.bind(client)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the removeListener
call will not remove anything here.
bind()
returns a new function every time it is called, so this function will be different from the one that was registered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to store the generated function somewhere if you want to remove it later:
const handler = instance.onEvent.bind(instance);
on('some event', handler);
removeListener('some event', handler);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we might also just call removeAllListeners
here instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thats not good at all. I will work on a fix later today.
Regarding removeAllListeners
I prefer explicitly removing the listeners that we set up in listenToSocketEvents
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description
We've detected some instances where
Client
would process calls even afterChannel
has disconnected. This PR makes sureClient
does not receive any events fromsocket
whendisconnect
is called or when thedisconnect
event is fired.[] It needs and includes Unit Tests
Changes in Client or Server public APIs
[] It includes documentation for these changes in
/doc
.