Skip to content

Commit

Permalink
Disable the deadlock_detection feature by default (#195)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
EightFactorial and mat-1 authored Dec 10, 2024
1 parent 0710996 commit 2feef49
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 53 deletions.
46 changes: 23 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ sha2 = "0.10.8"
simdnbt = "0.6"
socks5-impl = "0.5.17"
syn = "2.0.90"
thiserror = "2.0.5"
thiserror = "2.0.6"
tokio = "1.42.0"
tokio-util = "0.7.13"
tracing = "0.1.41"
Expand Down
2 changes: 1 addition & 1 deletion azalea-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bevy_tasks = { workspace = true }
bevy_time = { workspace = true }
derive_more = { workspace = true, features = ["deref", "deref_mut"] }
minecraft_folder_path = { workspace = true }
parking_lot = { workspace = true, features = ["deadlock_detection"] }
parking_lot = { workspace = true }
regex = { workspace = true }
reqwest = { workspace = true }
simdnbt = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions azalea/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 }
Expand All @@ -48,6 +48,7 @@ uuid = { workspace = true }

[dev-dependencies]
criterion = { workspace = true }
parking_lot = { workspace = true, features = ["deadlock_detection"] }
rand = { workspace = true }

[features]
Expand Down
2 changes: 1 addition & 1 deletion azalea/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
51 changes: 26 additions & 25 deletions azalea/examples/testbot/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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);

Expand All @@ -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]
Expand Down

0 comments on commit 2feef49

Please sign in to comment.