subscriber: always ignore lock poisoning #1063
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
tracing-subscriber
can conditionally useparking_lot
's locks ratherthan
std::sync
's locks, when a feature flag is enabled. Becauseparking_lot
's locks do not poison on panics, whilestd::sync
's locksdo, the APIs differ slightly. Currently, we handle this by wrapping the
parking_lot
RwLock
in a newtype that returnsResult
s, likestd::sync::RwLock
does, but always returnsOk
. Then, potentiallypoisoned locks are handled at the callsite.
However, this is unnecessary (and potentially incorrect). Because locks
may or may not be poisoned depending on the feature flag,
tracing-subscriber
can't rely on poisoning for correctness. Doing sowould mean potentially different behavior between
std::sync
andparking_lot
. Currently, because a number oftracing-subscriber
functions are called in
Drop
impls, we don't panic when a lock ispoisoned, to avoid double panics. Most cases where a lock might be
poisoned are handled by returning early with a default value. However,
with
parking_lot
enabled, this will never happen, and it addscomplexity at the callsite.
Solution
This branch changes our approach to wrap
std::sync
's locks and usePoisonError::into_inner
to ignore poisoning. This results in moreconsistent behavior between the
parking_lot
feature andstd
, andalso probably improves performance a bit with
parking_lot
--- we don'thave to have extra code for handling an
Err
case that will neverhappen (although rustc might be smart enough to optimize it away). Also,
the callsites are simpler since they never have to handle poisoning, and
we can't accidentally
unwrap
in aDrop
impl.I also removed the janky user-space thread-local implementation used by
CurrentSpan
, and changed it to just use thethread-local
crate. Wealready depend on that crate for the
Registry
, and my DIYimplementation has some performance issues. So, I removed it.
Depends on #1062