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

Remove socket listeners on channel disconnect #1375

Merged

Conversation

lodoyun
Copy link
Contributor

@lodoyun lodoyun commented Mar 5, 2019

Description
We've detected some instances where Client would process calls even after Channel has disconnected. This PR makes sure Client does not receive any events from socket when disconnect is called or when the disconnect event is fired.

[] It needs and includes Unit Tests

Changes in Client or Server public APIs

[] It includes documentation for these changes in /doc.

@@ -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));

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.

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

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@jcague jcague left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lodoyun lodoyun merged commit a30fc2c into lynckia:master Mar 7, 2019
@lodoyun lodoyun deleted the fix/stopListeningToSocketEventsAfterDisconnect branch September 3, 2019 10:52
Arri98 pushed a commit to Arri98/licode that referenced this pull request Apr 6, 2021
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

Successfully merging this pull request may close these issues.

3 participants