-
Notifications
You must be signed in to change notification settings - Fork 980
fix(instrumentation-fetch): release HTTP connection when response body is cancelled #5894
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(instrumentation-fetch): release HTTP connection when response body is cancelled #5894
Conversation
…r to release HTTP connection
|
For reference, here’s a patch that applies |
|
All tests passed locally:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5894 +/- ##
=======================================
Coverage 95.07% 95.07%
=======================================
Files 308 308
Lines 8037 8037
Branches 1626 1626
=======================================
Hits 7641 7641
Misses 396 396 🚀 New features to boost your workflow:
|
pichlermarc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this! Could you please add a test for us to see that the behavior is correct now and also for us to prevent any regressions in the future :)
… ensure span ends on reader.cancel()
|
Hi @pichlermarc, I've added a test case that simulates
I'm testing this way because |
…odel and drop resClone; keep eager consumption for now (see PR open-telemetry#5894)
|
Hi @legendecas , I’ve addressed the feedback. Could you please let me know if this PR meets the criteria for merging, or if there’s anything else you’d like me to change? |
Which problem is this PR solving?
What
When using
FetchInstrumentation, if a user cancels theResponse.bodyreader, the underlying HTTP connection is not released.Why
The instrumentation clones the
Responseand continuously reads from the clone to track span completion. Even if the user cancels the original response, the clone reader continues reading, preventing the browser from freeing the HTTP connection. This breaks integrations such asflv.jswhereplayer.destroy()is expected to close network connections.Fixes #5883
Short description of the changes
Introduce a
withCancelPropagationhelper that wraps the original response body. When the user cancels, the cancel signal is propagated to the clone's reader, ensuring both readers stop and the HTTP connection is released properly.Type of change
How Has This Been Tested?
flv.jsplayer with@opentelemetry/instrumentation-fetchenabled.player.destroy().Checklist: