From a4d24779bc7ec27e2277b6a540ed138c988e7667 Mon Sep 17 00:00:00 2001 From: Rasmus Viitanen Date: Mon, 8 Mar 2021 14:29:43 +0100 Subject: [PATCH] use replace instead of insert to add extension 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`. --- tracing-distributed/src/telemetry_layer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tracing-distributed/src/telemetry_layer.rs b/tracing-distributed/src/telemetry_layer.rs index ca9abc9..ddb8243 100644 --- a/tracing-distributed/src/telemetry_layer.rs +++ b/tracing-distributed/src/telemetry_layer.rs @@ -99,7 +99,7 @@ where for span_ref in path.into_iter() { let mut write_guard = span_ref.extensions_mut(); - write_guard.insert::>(LazyTraceCtx( + write_guard.replace::>(LazyTraceCtx( TraceCtx { trace_id: local_trace_root.trace_id.clone(), parent_span: None, @@ -122,7 +122,7 @@ where for span_ref in path.into_iter() { let mut write_guard = span_ref.extensions_mut(); - write_guard.insert::>(LazyTraceCtx( + write_guard.replace::>(LazyTraceCtx( TraceCtx { trace_id: already_evaluated.trace_id.clone(), parent_span: None,