Change strategy for detaching contexts#383
Merged
Merged
Conversation
Codecov Report
@@ Coverage Diff @@
## master #383 +/- ##
==========================================
+ Coverage 94.96% 94.98% +0.02%
==========================================
Files 162 162
Lines 6968 6996 +28
==========================================
+ Hits 6617 6645 +28
Misses 351 351
|
reyang
reviewed
Oct 30, 2020
| bool Detach(Token &token) noexcept override | ||
| { | ||
| if (!(token == GetStack().Top())) | ||
| if (!GetStack().Contains(token)) |
Member
There was a problem hiding this comment.
I guess in 99% of the chance GetStack().Top() would equal to the token, so it might worth a special case optimization (might save few CPU cycles on L188?):
if (token == GetStack().Top())
{
GetStack().Pop();
return true;
}
// check if token exists on the stack and pop items above it
Contributor
Author
There was a problem hiding this comment.
Good point. Added.
GerHobbelt
pushed a commit
to GerHobbelt/opentelemetry-cpp
that referenced
this pull request
Aug 31, 2025
Update dependency bazel to v8.3.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With the existing solution, users had to make sure that they always detached contexts in exactly the reverse orders they were attached. So, for attaching contexts in the order
A - B - C, they have to be detached in the orderC - B - A. If a user would try to detachBbeforeC, this would lead to an error (which the user doesn't notice if they don't explicitly check the return code ofDetach). This can lead problems if a user forgets to detach a context (in this case, this context would never be detached).With this PR the strategy is changed so that if a context is detached, all it's active child contexts are detached too. So if a user attaches contexts in the order
A - B - C, and then detachedB, bothBandCwill be detached. This is a much more robust solution that will avoid dangling contexts.Fixes #219.