From 1da1d57c111e14ed89516c9767b5a42c7a7d15a4 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 21 Aug 2025 15:31:56 +0200 Subject: [PATCH] Panic mutexes that can't lock for 30 seconds, in debug builds (#7468) I'm trying to debug a suspected deadlock in the CI for https://github.com/emilk/egui/pull/7467 Since we use our own mutex wrappers, we can just panic if the lock is too slow. Ugly and effective :) --- crates/epaint/src/mutex.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/epaint/src/mutex.rs b/crates/epaint/src/mutex.rs index 465722c1..ef1b3a6c 100644 --- a/crates/epaint/src/mutex.rs +++ b/crates/epaint/src/mutex.rs @@ -23,7 +23,13 @@ mod mutex_impl { #[inline(always)] pub fn lock(&self) -> MutexGuard<'_, T> { - self.0.lock() + if cfg!(debug_assertions) { + self.0 + .try_lock_for(std::time::Duration::from_secs(30)) + .expect("Looks like a deadlock!") + } else { + self.0.lock() + } } } }