From 0ccdd30f445d72dbb7f93870432a2a3a6aee48aa Mon Sep 17 00:00:00 2001 From: iroiro147 Date: Sat, 1 Aug 2026 10:19:36 +0530 Subject: [PATCH] test(relay): serialize flaky trace_context_lookup callsite test under ENV_LOCK (#3929) trace_context_lookup_does_not_enable_callsites intermittently failed under the parallel buzz-relay lib suite (1/6 on clean main, 2/6 on #3844 head) while passing 100% standalone. tracing's callsite interest cache is global per callsite, not per-subscriber: a neighbor test that registers a global default dispatcher can poison this callsite's cached interest before the thread-local with_default filter runs, so the !enabled! probe consults a stale entry. Serialize this test against the other global-state tests by taking the same ENV_LOCK mutex they already hold (:498+), so no global-dispatcher registration can overlap it. This matches the existing repo convention; a unique per-run callsite target (the other suggested fix) was rejected because tracing's enabled! target position requires a constant and will not accept a runtime &str (E0435). Verified: under the real repro (cargo test -p buzz-relay --lib, the full parallel suite), this test no longer appears among failures across 3 consecutive runs. The 9 remaining suite failures are all pre-existing api::media/api::admin sidecar/env-gated cases on clean main, unrelated to this test. Filtered telemetry suite passes 8/8. Found while reproducing the reporter's six consecutive full-suite runs. Refs block/buzz#3929 Signed-off-by: iroiro147 --- crates/buzz-relay/src/telemetry.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/buzz-relay/src/telemetry.rs b/crates/buzz-relay/src/telemetry.rs index 91bd92f0f3..1543de0a74 100644 --- a/crates/buzz-relay/src/telemetry.rs +++ b/crates/buzz-relay/src/telemetry.rs @@ -473,6 +473,16 @@ mod tests { #[test] fn trace_context_lookup_does_not_enable_callsites() { + // #3929: this test intermittently failed under the parallel suite + // because `tracing`'s callsite *interest* cache is global per + // callsite, not per-subscriber. A neighbor test that registers a + // global default dispatcher can poison this callsite's cached + // interest before our thread-local `with_default` runs, so the probe + // consults a stale entry. Serialize against the other global-state + // tests via the shared ENV_LOCK (the same mutex they already take), + // so no global-dispatcher registration can overlap this test. + let _guard = ENV_LOCK.lock().unwrap(); + let context_lookup = TraceContextLookup::default(); let subscriber = tracing_subscriber::registry().with( context_lookup