Rust’s standard mutex has a habit that developer Armin Ronacher wants gone. Mutex poisoning, the flag that marks a lock as broken after a thread panics while holding it, should be removed or made the exception, he argues, as the Rust libs team debates making non-poisoning locks the default in the next edition.
Ronacher says he has hit the problem many times and can’t recall it ever helping him.
How mutex poisoning works
If a thread panics while it holds a std::sync::Mutex, Rust marks that mutex as poisoned, and every later lock() call returns a PoisonError. The design assumes some objects have internal rules that must always hold. A panic mid-update could break them, so later users get a warning.
Ronacher says he hasn’t seen code that handles the warning correctly. After a panic with a lock held, he sees two sensible choices: stop the process, or keep going and disregard the flag. Compiling with panic set to abort gives the first. With unwinding, the usual lock().unwrap() pattern gives neither, since each later lock becomes another panic and the process lingers.
Rust’s Josh Triplett has said the standard library has never seen a report of anyone trying to recover from poison.
Deadlocks and failures that never end
The error type itself causes trouble. A PoisonError has to hold the lock guard, because that’s how code gets at the data if it decides to ignore the flag. Keeping the error alive therefore keeps the lock held. A plain m.lock()? in a function returning Box<dyn Error> can leave the mutex locked for as long as the error exists. Ronacher points to projects including cc-switch, PC-AI and ox-embed-server where a fallback branch locked the same mutex again while the hidden error still owned the guard.
Poisoning also fails slowly. The first panic happens once, often far from the code that breaks later. Afterward each lock().unwrap() on that mutex panics as well. Thread pools, request handlers, tokio tasks and FFI boundaries all survive panics, so the process stays alive but can’t do its job. Examples he cites:
- In the Rust Language Server, a failed cargo build panicked with a global lock held and blocked every later run.
- Mozilla’s application-services saw PoisonError climb to fifth place in its crash statistics and moved to parking_lot, which has no poisoning.
- A Neon safekeeper on staging failed every timeline lookup after one panic, and the original panic couldn’t be found in the logs.
Test suites suffer too: a single failing test poisons a shared static, and later tests fail with PoisonError. He says this happened in cargo, deno, polars and rustc.
Recovery isn’t clean either
Code that does recover with into_inner() leaves the flag set, so each later access takes the recovery path again. For the first nine years after poisoning landed, the flag couldn’t even be cleared: clear_poison only arrived in Rust 1.77. Ronacher lists projects that repeated expensive work or logged the same warning on every access after a single panic.
The standard library already ignores it
Rust’s own code often ignores poisoning. Standard I/O has done so since March 2015, two months before Rust 1.0, because any poison there must come from user code the lock doesn’t guard. The panic output capture, the backtrace lock and the WASI environment lock do the same, and an open pull request would move the standard library’s internal mutexes to a non-poisoning type.
The ecosystem has drifted away from mutex poisoning too. Tokio’s locks don’t poison, and it wraps the standard mutex in an adapter that strips the flag. Wasmtime, crossbeam-channel and tracing-subscriber ignore poisoning, and rust-analyzer moved to parking_lot after cancellation poisoned its solver. The parking_lot maintainer has called poisoning an anti-feature.
The memory-safety argument gets a rebuttal too. In one tokio case, a contributor needed into_inner to unlink a waiter during drop. Otherwise the list would keep a dangling pointer, so poisoning blocked a memory-safety fix.
Inconsistent by design
Why poison a Mutex but not a RefCell? If the point is protecting against code that breaks an invariant and panics, the same logic applies. Tokio catches every task panic, so with a LocalSet the panic comes back as a JoinError and the next borrow() can read broken state. Nobody asks for RefCell to poison. The standard library is also uneven: LazyLock poisons permanently, OnceLock never poisons, and Mutex poisons but lets you recover. Early returns through the ? operator leave the same broken state behind an unpoisoned lock.
What Ronacher wants next
Ronacher would stabilize std::sync::nonpoison and have std::sync::Mutex point to it by default. Teams that want poisoning could add a separate Poison<T> wrapper, usable with RefCell or tokio types too. He notes that tying poisoning to mutexes is a historical accident.
He considers the counter-proposal worst of all: keep poisoning but make lock() panic instead of returning a Result. That would fix the held-guard problem, but make the slow outage the only behavior, which is what lock().unwrap() does today. He grants that the other side has a serious defense, and adds that most of what Oxide ships aborts on panic anyway.
For now the decision sits with the libs team. If non-poisoning becomes the default in the next edition, Rust programmers would need to decide whether any of their code relied on mutex poisoning.