From 10f774718ccf06d50ed5d8e82ebe16a4244479e8 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Wed, 15 Sep 2021 19:45:23 -0700 Subject: [PATCH] subscriber: clear per-layer interest when short circuiting (#1569) Currently, when evaluating `register_callsite` for a stack containing per-layer filters, the intermediate `Interest` from combining the per layer filters' `Interest`s is stored in the thread-local `FilterState`. When all per-layer filters have been evaluated, we reach the `Registry`, which clears the `FilterState` and bubbles the `Interest` back up. However, when a _global_ filter in the stack returns `Interest::never`, we short-circuit, and don't reach the `Registry`. This means the `Interest` state is not cleared. This branch adds code in `Layered` to ensure the per-layer filter state is cleared when a global filter short circuits `Interest` evaluation. This fixes #1563. Signed-off-by: Eliza Weisman --- tracing-subscriber/src/subscribe/layered.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tracing-subscriber/src/subscribe/layered.rs b/tracing-subscriber/src/subscribe/layered.rs index e912998b72..898d03c0a2 100644 --- a/tracing-subscriber/src/subscribe/layered.rs +++ b/tracing-subscriber/src/subscribe/layered.rs @@ -380,6 +380,12 @@ where // If the outer layer has disabled the callsite, return now so that // the inner layer/subscriber doesn't get its hopes up. if outer.is_never() { + // If per-layer filters are in use, and we are short-circuiting + // (rather than calling into the inner type), clear the current + // per-layer filter interest state. + #[cfg(feature = "registry")] + drop(filter::FilterState::take_interest()); + return outer; }