diff options
| author | Zeyla Hellyer <[email protected]> | 2018-08-02 17:04:16 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2018-08-02 17:05:29 -0700 |
| commit | f064d65486d0c8a3c510ee398e7d0bbf6b283bdb (patch) | |
| tree | dedd5749a537461a10a5d7d3af4a68e61e848383 /src | |
| parent | Add a test-case for no delimiters (diff) | |
| download | serenity-f064d65486d0c8a3c510ee398e7d0bbf6b283bdb.tar.xz serenity-f064d65486d0c8a3c510ee398e7d0bbf6b283bdb.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/dispatch.rs | 13 |
1 files changed, 12 insertions, 1 deletions
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 + }) } } }; |