-
Notifications
You must be signed in to change notification settings - Fork 790
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
Baggage API: Thread-safety #2298
Baggage API: Thread-safety #2298
Conversation
Created as a draft to get feedback on the breaking behavior change. If we're OK with this, I'll update changelog with a note and convert to a real PR. |
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.
LGTM, it is not a breaking change from the signature perspective.
It does change the behavior which might break the users if they rely on certain behavior, but I feel that if we leave it as is (which is a bit confusing I guess?) we probably will end up surprising/confusing more users moving forward.
Codecov Report
@@ Coverage Diff @@
## main #2298 +/- ##
==========================================
+ Coverage 79.61% 79.66% +0.04%
==========================================
Files 233 233
Lines 7325 7346 +21
==========================================
+ Hits 5832 5852 +20
- Misses 1493 1494 +1
|
/// cref="Current"/> either set <see cref="Current"/> to a new instance | ||
/// or use one of the static methods that target <see cref="Current"/> | ||
/// as the default source. Examples: | ||
/// <code> |
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.
can you reverse the order of the example codes below, so that it matches the Note: section.
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.
I reversed your request to reverse the code examples and instead reversed the notes. I wanted to have the preferred approach (static methods) first. I also updated the README to the safer static API.
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.
I reversed your request to reverse the code examples and instead reversed the notes.
This makes my day 😵😆
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.
Ya had some fun with that one 😄 Also very excited about the pun opportunities for my next PR: "Lost Baggage"
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.
LGTM.
Suggested to modify the readme to guide users to use static (Baggage.SetBaggage).
This is a follow-up to the discussion on #2284.
Changes
Breaking behavior changes
Previously if you called SetBaggage, RemoveBaggage, or ClearBaggage on a Baggage instance it would mutate Baggage.Current. For example:
Now you have to explicitly set back the instance. Like this:
If you use the statics, this is done automatically:
The reason for the change is Baggage is a
readonly struct
so when you do Baggage.Current you get a copy. You can write code like this:Basically when the instance SetBaggage executes it doesn't know if it is current or not. I thought about managing a flag on Baggage so it could know if it was attached or not, but it is readonly so there's no (safe) way to update the flag. We could compare it back to Current, but another thread could have already changed it. I decided the best option was to always treat it as detached and allow the user to make the decision about whether or not it should become the "Current" version or not. I think this makes the API more consistent and usable but it will break anyone reliant on this behavior today.
Alternatively, we could [Obsolete] Baggage and introduce something new with a contract.
TODOs
CHANGELOG.md
updated for non-trivial changes