Skip to content

Commit

Permalink
use replace instead of insert to add extension
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Rasmus Viitanen authored and Fishrock123 committed Mar 12, 2021
1 parent 53aeced commit 620ec61
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tracing-distributed/src/telemetry_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ where

for span_ref in path.into_iter() {
let mut write_guard = span_ref.extensions_mut();
write_guard.insert::<LazyTraceCtx<SpanId, TraceId>>(LazyTraceCtx(
write_guard.replace::<LazyTraceCtx<SpanId, TraceId>>(LazyTraceCtx(
TraceCtx {
trace_id: local_trace_root.trace_id.clone(),
parent_span: None,
Expand All @@ -122,7 +122,7 @@ where

for span_ref in path.into_iter() {
let mut write_guard = span_ref.extensions_mut();
write_guard.insert::<LazyTraceCtx<SpanId, TraceId>>(LazyTraceCtx(
write_guard.replace::<LazyTraceCtx<SpanId, TraceId>>(LazyTraceCtx(
TraceCtx {
trace_id: already_evaluated.trace_id.clone(),
parent_span: None,
Expand Down

0 comments on commit 620ec61

Please sign in to comment.