# Rust: thread 'main' panicked: called `Result::unwrap()` on an `Err` value: PoisonError { .. } — poisoned lock: another task failed inside

**Code:** `PoisonError: poisoned lock: another task failed inside` · **Category:** Rust · **Seen on:** Rust

A thread panicked while holding a `Mutex`/`RwLock`, so the lock is "poisoned" and `lock().unwrap()` panics for others.

## Meaning

Fix the original panic first (it happened in another thread: look earlier in the log). Then either propagate (`lock().unwrap()` is intentional to fail fast) or recover with `lock().unwrap_or_else(|e| e.into_inner())` if state is still valid. `parking_lot::Mutex` doesn't poison.

## Common causes

- A thread panicked while holding the guard
- `unwrap()` on a previously panicked mutex
- Panics inside critical sections (indexing, unwrap)
- Test threads sharing global mutexes
- Async tasks panicking with guards

## Quick fix

1. Fix the root-cause panic that poisoned the lock
2. Recover: `mutex.lock().unwrap_or_else(|e| e.into_inner())`
3. Consider `parking_lot::Mutex` (no poisoning) when appropriate

## Detailed fix by platform

### Rust

1. `let guard = m.lock().unwrap_or_else(|poisoned| poisoned.into_inner());`

## How to diagnose

1. **Root cause** — First panic?
2. **State** — Still valid?
3. **Alternative** — parking_lot?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/rust/poisonerror-mutex-poisoned)
