-
Notifications
You must be signed in to change notification settings - Fork 178
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
Comments
8 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 bothevent.node.res.on('close')
andwriter.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 (whenautoclose
is set to true). So, I propose we removeevent.node.res.on('close')
from theonClosed
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 onevent.node.res.on('close')
if they want.Logs
No response
The text was updated successfully, but these errors were encountered: