Skip to content

Commit 77e87c2

Browse files
committed
Fix: Remove panic-in-panic failure when running tests
Symptom: ``` thread panicked while processing panic. aborting. ``` It seems to be a MPSC channel hangup problem, where the reciever does not exist any more when transmitting value through channel. Root cause is not fully understood but a guess is that we get some kind of race condition between multiple test cases setting and resetting the `catch_panic` functionality. Please Note! Since `std::panic::set_hook` is global, we might have a race condition when multiple threads are running tests in parallel. In that case, panics from other threads might interfere with each other in the custom hook. Leaving aa-is for now.
1 parent 57d4e91 commit 77e87c2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ Other known limitations:
7272
only try candidates within the given range `10.0..100.0`, but can also try other
7373
values like -10.0 and will ultimately try to shrink toward zero.
7474

75+
* Monkey test uses the global panic hook to catch panics in code under test and
76+
this can interfere with other code that also modifies the panic hook during
77+
testing.
78+
Since the panic hook is a global resource, it migth also have unintended
79+
effects in multithreaded testing due to limitations in the current panic hook
80+
handling in Monkey Test.
81+
7582
For details on recent changes, see the [CHANGELOG](CHANGELOG.md).
7683

7784
## Key design principles

src/config.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ where
255255
E: std::fmt::Debug + std::panic::UnwindSafe + Clone + 'static,
256256
P: std::panic::RefUnwindSafe + Fn(E) -> Result<(), String>,
257257
{
258+
// Please Note! Since `std::panic::set_hook` is global, we might have a race
259+
// condition here if multiple threads are running tests in parallel. In that
260+
// case, panics from other threads might be caught here and hooks might
261+
// interfere with each other. Leaving as-is for now.
262+
258263
move |example: E| {
259264
let original_panic_hook = std::panic::take_hook();
260265
let (tx, rx) = mpsc::channel();
@@ -266,7 +271,10 @@ where
266271
if let Some(loc) = info.location() {
267272
let location_text =
268273
format! {"in file '{}' at line {}", loc.file(), loc.line()};
269-
tx.send(location_text).unwrap();
274+
275+
// Ignoring send errors, since there is nothing to do if
276+
// receiver has hung up. We are then out of test scope anyway.
277+
let _ = tx.send(location_text);
270278
}
271279
}));
272280

0 commit comments

Comments
 (0)