Deadlock when capturing a backtrace from allocator during panic with test output capturing enabled #130187
Labels
A-backtrace
Area: Backtraces
C-bug
Category: This is a bug.
regression-from-stable-to-stable
Performance or correctness regression from one stable version to another.
I tried this code (minimized from a larger testcase):
Compiled with
rustc --test main.rs
.I expected to see this happen: the test successfully panics and exits.
Instead, this happened: the test deadlocks.
Relevant section of backtrace:
This is specifically related to output capturing from the test runner, running the same code as a non-test binary or with
--nocapture
works perfectly.Meta
This worked in
1.80.1
andnightly-2024-07-13
, it started failing in1.81.0
andnightly-2024-07-14
.The deadlock was introduced by #127397 (cc @jyn514).
The lock is first taken when starting to print from the default panic hook:
rust/library/std/src/panicking.rs
Line 257 in 26b2b8d
The first print to the output then happens:
rust/library/std/src/panicking.rs
Line 258 in 26b2b8d
For captured output this requires then reallocating the
Vec
storing the capture, so it calls into the allocator, hitting theBacktrace::force_capture
because this is the first allocation in the test. This attempts to re-entrantly acquire the lock a second time, deadlocking:rust/library/std/src/backtrace.rs
Line 326 in 26b2b8d
The text was updated successfully, but these errors were encountered: