[API] Fix issue with Baggage.Current leaking#7191
Conversation
Fix issue with `Baggage.Current` updates made in a child async flow that could leak back into the parent flow.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7191 +/- ##
==========================================
- Coverage 89.86% 89.80% -0.07%
==========================================
Files 275 275
Lines 13852 13856 +4
==========================================
- Hits 12448 12443 -5
- Misses 1404 1413 +9
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Add PR number.
There was a problem hiding this comment.
Pull request overview
This PR fixes an ambient-context bug where Baggage.Current mutations performed in child async/parallel flows could leak back into the parent flow by removing shared mutable state from the runtime context slot.
Changes:
- Update
Baggageto store an immutableBaggageHolderin the runtime context slot and replace the holder on every update (instead of mutating a shared holder instance). - Add/adjust unit tests to validate isolation of
Baggage.Currentacross async and parallel flows. - Add a changelog entry describing the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| test/OpenTelemetry.Api.Tests/BaggageTests.cs | Adds/updates tests for async/parallel flow isolation of Baggage.Current. |
| src/OpenTelemetry.Api/CHANGELOG.md | Documents the baggage leak fix in Unreleased notes. |
| src/OpenTelemetry.Api/Baggage.cs | Implements the leak fix by replacing the context slot value on updates and making the holder immutable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address review feedback.
|
There were some previously reverted changes to this scope. See the issue #3257 Revert itself #5227 @martinjt, @danelson, @CodeBlanch, FYI |
Add more unit tests for the issue.
Changes
Fix issue with
Baggage.Currentupdates made in a child async flow that could leak back into the parent flow.I got Copilot to write most of this PR. It seems reasonable to me, but this probably needs quite a critical review.
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)