diff options
| author | EightFactorial <29801334+EightFactorial@users.noreply.github.com> | 2024-12-10 14:37:35 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-10 16:37:35 -0600 |
| commit | 2feef494718009dbcb5c62ef1e58c84c36e8bcbf (patch) | |
| tree | 8f2ebbc219c14ca383d3b392c3d03aa90c9bf8ac /azalea | |
| parent | 07109964ad8486a9d4caee430ccadf7f7fc3d648 (diff) | |
| download | azalea-drasl-2feef494718009dbcb5c62ef1e58c84c36e8bcbf.tar.xz | |
Disable the `deadlock_detection` feature by default (#195)
* Disable the `deadlock_detection` feature by default
Fixes conflicts with any packages that enable parking_lot's `send_guard` feature
* move testbot deadlock detection to a function and add additional comments
---------
Co-authored-by: mat <git@matdoes.dev>
Diffstat (limited to 'azalea')
| -rw-r--r-- | azalea/Cargo.toml | 5 | ||||
| -rwxr-xr-x | azalea/README.md | 2 | ||||
| -rw-r--r-- | azalea/examples/testbot/main.rs | 51 |
3 files changed, 30 insertions, 28 deletions
diff --git a/azalea/Cargo.toml b/azalea/Cargo.toml index a658c3a8..63e84f54 100644 --- a/azalea/Cargo.toml +++ b/azalea/Cargo.toml @@ -8,7 +8,7 @@ repository = { workspace = true } [package.metadata.release] pre-release-replacements = [ - { file = "README.md", search = "`azalea = \"[a-z0-9\\.-]+\"`", replace = "`azalea = \"{{version}}\"`" }, + { file = "README.md", search = "`azalea = \"[a-z0-9\\.-]+\"`", replace = "`azalea = \"{{version}}\"`" }, ] [dependencies] @@ -37,7 +37,7 @@ futures = { workspace = true } futures-lite = { workspace = true } nohash-hasher = { workspace = true } num-traits = { workspace = true } -parking_lot = { workspace = true, features = ["deadlock_detection"] } +parking_lot = { workspace = true } priority-queue = { workspace = true } rustc-hash = { workspace = true } serde = { workspace = true, optional = true } @@ -48,6 +48,7 @@ uuid = { workspace = true } [dev-dependencies] criterion = { workspace = true } +parking_lot = { workspace = true, features = ["deadlock_detection"] } rand = { workspace = true } [features] diff --git a/azalea/README.md b/azalea/README.md index e7f52cd6..a135add4 100755 --- a/azalea/README.md +++ b/azalea/README.md @@ -99,7 +99,7 @@ Note: If you get a `SetLoggerError`, it's because you have multiple loggers. Aza ## Deadlocks -If your code is simply hanging, it might be a deadlock. Copy the deadlock block in [`azalea/examples/testbot.rs`](https://github.com/azalea-rs/azalea/blob/main/azalea/examples/testbot/main.rs) to the beginning of your code and it'll print a long backtrace if a deadlock is detected. +If your code is simply hanging, it might be a deadlock. Enable `parking_lot`'s `deadlock_detection` feature and copy the deadlock block in [`azalea/examples/testbot.rs`](https://github.com/azalea-rs/azalea/blob/main/azalea/examples/testbot/main.rs) to the beginning of your code and it'll print a long backtrace if a deadlock is detected. ## Backtraces diff --git a/azalea/examples/testbot/main.rs b/azalea/examples/testbot/main.rs index e7d68d5e..9c8d1085 100644 --- a/azalea/examples/testbot/main.rs +++ b/azalea/examples/testbot/main.rs @@ -14,8 +14,8 @@ mod commands; pub mod killaura; -use std::sync::Arc; use std::time::Duration; +use std::{sync::Arc, thread}; use azalea::brigadier::command_dispatcher::CommandDispatcher; use azalea::ecs::prelude::*; @@ -37,30 +37,7 @@ const PATHFINDER_DEBUG_PARTICLES: bool = false; #[tokio::main] async fn main() { - { - use std::thread; - use std::time::Duration; - - use parking_lot::deadlock; - - // Create a background thread which checks for deadlocks every 10s - thread::spawn(move || loop { - thread::sleep(Duration::from_secs(10)); - let deadlocks = deadlock::check_deadlock(); - if deadlocks.is_empty() { - continue; - } - - println!("{} deadlocks detected", deadlocks.len()); - for (i, threads) in deadlocks.iter().enumerate() { - println!("Deadlock #{i}"); - for t in threads { - println!("Thread Id {:#?}", t.thread_id()); - println!("{:#?}", t.backtrace()); - } - } - }); - } + thread::spawn(deadlock_detection_thread); let account = Account::offline(USERNAME); @@ -85,6 +62,30 @@ async fn main() { .unwrap(); } +/// Runs a loop that checks for deadlocks every 10 seconds. +/// +/// Note that this requires the `deadlock_detection` parking_lot feature to be +/// enabled, which is only enabled in azalea by default when running in debug +/// mode. +fn deadlock_detection_thread() { + loop { + thread::sleep(Duration::from_secs(10)); + let deadlocks = parking_lot::deadlock::check_deadlock(); + if deadlocks.is_empty() { + continue; + } + + println!("{} deadlocks detected", deadlocks.len()); + for (i, threads) in deadlocks.iter().enumerate() { + println!("Deadlock #{i}"); + for t in threads { + println!("Thread Id {:#?}", t.thread_id()); + println!("{:#?}", t.backtrace()); + } + } + } +} + #[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] pub enum BotTask { #[default] |
