TryLockError::Poisoned
RustERRORCommonConcurrency
try_lock failed — mutex is poisoned
Quick Answer
Same recovery as PoisonError: use into_inner() or propagate the error.
What this means
try_lock() returned Err(TryLockError::Poisoned) because a thread panicked while holding the lock.
Why it happens
- 1Underlying mutex is poisoned (see PoisonError)
Fix
Recover with try_lock
Recover with try_lock
use std::sync::TryLockError;
match mutex.try_lock() {
Ok(g) => use_guard(g),
Err(TryLockError::Poisoned(e)) => use_guard(e.into_inner()),
Err(TryLockError::WouldBlock) => { /* retry later */ }
}Why this works
Distinguishes poison from contention, allowing appropriate handling for each.
Code examples
Triggerrust
// Same as PoisonError — thread panicked while holding lock
Sources
Official documentation ↗
Rust std::sync
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev