Skip to content

The emitter's removeListener is called twice #1139

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

Open
Hokid opened this issue Mar 25, 2025 · 2 comments · May be fixed by #1140
Open

The emitter's removeListener is called twice #1139

Hokid opened this issue Mar 25, 2025 · 2 comments · May be fixed by #1140

Comments

@Hokid
Copy link

Hokid commented Mar 25, 2025

When a client closes WS connection it calls the close method of the SubscriptionContext twice.

Triggered by:

socket.on('close', () => {
subscriptionConnection.close()
})

And here:

if (sc) {
sc.close && sc.close()
this.subscriptionContexts.delete(id)

It produces two removeListener calls:

const close = () => {
this.emitter.removeListener(topic, listener)
}

If there are two connected clients, and one of them closes the connection, then it is possible that the topic message listeners will be removed for both clients if the emitter implementation does not include a flag to check whether the subscription for a given listener has been removed. For example, mqemitter-redis does not do this and sends an unsubscribe command, so the second client will stop receiving new messages from the topic.

@mcollina
Copy link
Collaborator

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

Hokid added a commit to Hokid/mercurius that referenced this issue Mar 26, 2025
@Hokid Hokid linked a pull request Mar 26, 2025 that will close this issue
@Hokid
Copy link
Author

Hokid commented Mar 26, 2025

@mcollina Yes, check please

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 a pull request may close this issue.

2 participants