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

fix(sse): prevent onClosed from firing twice in EventStream #704

Merged
merged 9 commits into from
Jun 19, 2024

Conversation

joshmossas
Copy link
Contributor

@joshmossas joshmossas commented Mar 13, 2024

Fixes issue where onClosed always fires twice when using Server Sent Events.

The following changes were made to fix the issue:

  • remove redundant event.node.res.on('close') hook in onClosed method

The following changes were made to related documentation:

  • Remove redundant eventStream.close() invocation from ./examples/server-sent-events.ts
  • Remove redundant eventStream.close() invocation from ./docs/1.guide/6.websockets.md
  • Remove redundant eventStream.close() invocation from ./tests/sse.test.ts

eventStream.close() doesn't need to be called in onClosed by default because it is automatically handled when autoclose is set to true

🔗 Linked issue

Fixes #703

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Copy link

codecov bot commented Mar 19, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 79.76%. Comparing base (a58d7c9) to head (2c5574f).
Report is 84 commits behind head on main.

Files Patch % Lines
examples/server-sent-events.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #704      +/-   ##
==========================================
+ Coverage   77.83%   79.76%   +1.92%     
==========================================
  Files          47       54       +7     
  Lines        4286     5381    +1095     
  Branches      611      692      +81     
==========================================
+ Hits         3336     4292     +956     
- Misses        933     1070     +137     
- Partials       17       19       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pi0 pi0 changed the title [fix] prevent onClosed from firing twice in EventStream fix(sse): prevent onClosed from firing twice in EventStream Apr 17, 2024
@pi0 pi0 marked this pull request as draft April 17, 2024 14:10
@joshmossas joshmossas marked this pull request as ready for review April 18, 2024 03:28
@joshmossas joshmossas marked this pull request as draft April 18, 2024 03:29
@joshmossas
Copy link
Contributor Author

@pi0 Just curious what was the reason you marked this PR as a draft. I just wanted to check and see if I needed to change something on my end.

@pi0 pi0 marked this pull request as ready for review June 19, 2024 11:07
@pi0
Copy link
Member

pi0 commented Jun 19, 2024

Sorry for delay @joshmossas mainly needed to test it.

@pi0 pi0 changed the title fix(sse): prevent onClosed from firing twice in EventStream fix(sse): prevent onClosed from firing twice in EventStream Jun 19, 2024
@pi0 pi0 merged commit 624c2cb into unjs:main Jun 19, 2024
4 of 5 checks passed
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.

onClosed fires twice in server sent events
2 participants