use replace instead of insert to add extension#14
Open
rasviitanen wants to merge 1 commit intoinanna-malick:masterfrom
Open
use replace instead of insert to add extension#14rasviitanen wants to merge 1 commit intoinanna-malick:masterfrom
rasviitanen wants to merge 1 commit intoinanna-malick:masterfrom
Conversation
Previously `ExtensionsMut::insert` was used without a guarantee that we had exclusive access to a SpanRef's extensions. This could lead to a panic in the `insert` function in the case where the extension was inserted concurrently by multiple calls to `eval_ctx`. By using `replace` the assertion is ignored and it no longer matters whether we have exclusive access or not to a span in `eval_ctx`.
Author
|
@inanna-malick I don't want to put stress you, just tagging to make sure you are aware of this PR. Review in whatever pace is comfortable. |
This was referenced Mar 8, 2021
Contributor
|
These fixes were merged into the fork(s) I maintain & released:
|
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.
Previously
ExtensionsMut::insertwas used without a guarantee that we had exclusive access to a SpanRef's extensions.This could lead to a panic in the
insertfunction in the case where the extension was inserted concurrently by multiple calls toeval_ctx.By using
replacethe assertion is ignored and it no longer matters whether we have exclusive access or not to a span ineval_ctx.Example
Suppose we have have two parallel calls A and B to
eval_ctx:A is called with a span-tree with the following spans:
iter: [SpanId(1), SpanId(2), SpanId(3)]B is called with a span-tree with the following spans:
iter: [SpanId(1), SpanId(2), SpanId(4)]Both A and B enters the for loop and we suppose that they both adds
Span(1)andSpan(2)to theirpath.Then A continues to iterate over its spans and reaches
Span(3), which matches with the arm that eventually executes:Everything is OK so far.
Then B reaches the same loop once it proceeds to
SpanId(4).B then tries insert the extension for
SpanId(1), but it is already inserted by A.This is forbidden and
insertwill panic.Solution
As
LazyTraceCtxis private, there is no way for another Layer implementation to conflict with our extension, this means that we should be able to ignore the assertion ininsertand callreplaceinstead . It should be OK to replace old extensions as the replacement will be identical to what's already stored.The
replacefunction does the same thinginsertdoes but without the assertion (which we should be able to safely ignore):https://docs.rs/tracing-subscriber/0.2.15/src/tracing_subscriber/registry/extensions.rs.html#90-92