From f064d65486d0c8a3c510ee398e7d0bbf6b283bdb Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Thu, 2 Aug 2018 17:04:16 -0700 Subject: Fix potential dispatch cache deadlocking + log it Fix the dispatch functionality potentially deadlocking when a deadlock has occurred elsewhere (or a read/write lock is forever held elsewhere), and log when it happens, WARNing the user that a possible deadlock has happened. --- src/client/dispatch.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index 513efd7..b81b901 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -19,6 +19,8 @@ use typemap::ShareMap; use framework::Framework; #[cfg(feature = "cache")] use model::id::GuildId; +#[cfg(feature = "cache")] +use std::time::Duration; #[cfg(feature = "cache")] use super::CACHE; @@ -28,7 +30,16 @@ macro_rules! update { { #[cfg(feature = "cache")] { - CACHE.write().update(&mut $event) + CACHE.try_write_for(Duration::from_millis(10)) + .and_then(|mut lock| lock.update(&mut $event)) + .or_else(|| { + warn!( + "[dispatch] Possible deadlock: couldn't unlock cache to update with event: {:?}", + $event, + ); + + None + }) } } }; -- cgit v1.2.3