Skip to content

Commit 8b0b42d

Browse files
committed
tests: add test for tracing-error deadlock
This deadlock can happen when extensions of a span are locked while we visit either an event or attributes of a span. A `Debug` implementation can also try to access the extensions which results in a deadlock. See #59 and #95 for additional information.
1 parent 6c813c9 commit 8b0b42d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ futures-util = { version = "0.3", default-features = false }
5151
tokio = { version = "1", features = ["full"] }
5252
tokio-stream = "0.1"
5353
tracing = { version = "0.1.35", default-features = false, features = ["std", "attributes"] }
54+
tracing-error = "0.2.0"
5455
tracing-subscriber = { version = "0.3.0", default-features = false, features = ["registry", "std", "fmt"] }
5556

5657
[target.'cfg(not(target_os = "windows"))'.dev-dependencies]

src/layer.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,4 +1746,29 @@ mod tests {
17461746
)
17471747
);
17481748
}
1749+
1750+
#[test]
1751+
fn tracing_error_compatibility() {
1752+
let tracer = TestTracer(Arc::new(Mutex::new(None)));
1753+
let subscriber = tracing_subscriber::registry()
1754+
.with(
1755+
layer()
1756+
.with_error_fields_to_exceptions(false)
1757+
.with_tracer(tracer.clone()),
1758+
)
1759+
.with(tracing_error::ErrorLayer::default());
1760+
1761+
tracing::subscriber::with_default(subscriber, || {
1762+
let span = tracing::info_span!("Blows up!", exception = tracing::field::Empty);
1763+
let _entered = span.enter();
1764+
let context = tracing_error::SpanTrace::capture();
1765+
1766+
// This can cause a deadlock if `on_record` locks extensions while attributes are visited
1767+
span.record("exception", &tracing::field::debug(&context));
1768+
// This can cause a deadlock if `on_event` locks extensions while the event is visited
1769+
tracing::info!(exception = &tracing::field::debug(&context), "hello");
1770+
});
1771+
1772+
// No need to assert anything, as long as this finished (and did not panic), everything is ok.
1773+
}
17491774
}

0 commit comments

Comments
 (0)