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

onClosed fires twice in server sent events #703

Open
joshmossas opened this issue Mar 13, 2024 · 0 comments · May be fixed by #704
Open

onClosed fires twice in server sent events #703

joshmossas opened this issue Mar 13, 2024 · 0 comments · May be fixed by #704

Comments

@joshmossas
Copy link
Contributor

joshmossas commented Mar 13, 2024

Environment

Node: v20.11.1
H3: v1.11.1

Reproduction

https://github.com/joshmossas/h3-sse-on-closed-bug

Describe the bug

Calling eventStream.onClosed() in the current implementation registers a callback on both event.node.res.on('close') and writer.closed. This means that the callback will always fire twice, which could lead to some unexpected side effects, esp if users are interacting with things like database connections.

Additional context

We are already listening for event.node.res.on('close') by default (when autoclose is set to true). So, I propose we remove event.node.res.on('close') from the onClosed method because that case is already being handled in the default configuration.

I think if someone has chosen to set autoclose to false, they have already decided to take on additional work when it comes to cleanup. They can still manually register a callback on event.node.res.on('close') if they want.

Logs

No response

@joshmossas joshmossas linked a pull request Mar 13, 2024 that will close this issue
8 tasks
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.

1 participant