Skip to content

Commit 2feef49

Browse files
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>
1 parent 0710996 commit 2feef49

File tree

6 files changed

+55
-53
lines changed

6 files changed

+55
-53
lines changed

Cargo.lock

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ sha2 = "0.10.8"
7373
simdnbt = "0.6"
7474
socks5-impl = "0.5.17"
7575
syn = "2.0.90"
76-
thiserror = "2.0.5"
76+
thiserror = "2.0.6"
7777
tokio = "1.42.0"
7878
tokio-util = "0.7.13"
7979
tracing = "0.1.41"

azalea-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bevy_tasks = { workspace = true }
2727
bevy_time = { workspace = true }
2828
derive_more = { workspace = true, features = ["deref", "deref_mut"] }
2929
minecraft_folder_path = { workspace = true }
30-
parking_lot = { workspace = true, features = ["deadlock_detection"] }
30+
parking_lot = { workspace = true }
3131
regex = { workspace = true }
3232
reqwest = { workspace = true }
3333
simdnbt = { workspace = true }

azalea/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repository = { workspace = true }
88

99
[package.metadata.release]
1010
pre-release-replacements = [
11-
{ file = "README.md", search = "`azalea = \"[a-z0-9\\.-]+\"`", replace = "`azalea = \"{{version}}\"`" },
11+
{ file = "README.md", search = "`azalea = \"[a-z0-9\\.-]+\"`", replace = "`azalea = \"{{version}}\"`" },
1212
]
1313

1414
[dependencies]
@@ -37,7 +37,7 @@ futures = { workspace = true }
3737
futures-lite = { workspace = true }
3838
nohash-hasher = { workspace = true }
3939
num-traits = { workspace = true }
40-
parking_lot = { workspace = true, features = ["deadlock_detection"] }
40+
parking_lot = { workspace = true }
4141
priority-queue = { workspace = true }
4242
rustc-hash = { workspace = true }
4343
serde = { workspace = true, optional = true }
@@ -48,6 +48,7 @@ uuid = { workspace = true }
4848

4949
[dev-dependencies]
5050
criterion = { workspace = true }
51+
parking_lot = { workspace = true, features = ["deadlock_detection"] }
5152
rand = { workspace = true }
5253

5354
[features]

azalea/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Note: If you get a `SetLoggerError`, it's because you have multiple loggers. Aza
9999

100100
## Deadlocks
101101

102-
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.
102+
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.
103103

104104
## Backtraces
105105

azalea/examples/testbot/main.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
mod commands;
1515
pub mod killaura;
1616

17-
use std::sync::Arc;
1817
use std::time::Duration;
18+
use std::{sync::Arc, thread};
1919

2020
use azalea::brigadier::command_dispatcher::CommandDispatcher;
2121
use azalea::ecs::prelude::*;
@@ -37,30 +37,7 @@ const PATHFINDER_DEBUG_PARTICLES: bool = false;
3737

3838
#[tokio::main]
3939
async fn main() {
40-
{
41-
use std::thread;
42-
use std::time::Duration;
43-
44-
use parking_lot::deadlock;
45-
46-
// Create a background thread which checks for deadlocks every 10s
47-
thread::spawn(move || loop {
48-
thread::sleep(Duration::from_secs(10));
49-
let deadlocks = deadlock::check_deadlock();
50-
if deadlocks.is_empty() {
51-
continue;
52-
}
53-
54-
println!("{} deadlocks detected", deadlocks.len());
55-
for (i, threads) in deadlocks.iter().enumerate() {
56-
println!("Deadlock #{i}");
57-
for t in threads {
58-
println!("Thread Id {:#?}", t.thread_id());
59-
println!("{:#?}", t.backtrace());
60-
}
61-
}
62-
});
63-
}
40+
thread::spawn(deadlock_detection_thread);
6441

6542
let account = Account::offline(USERNAME);
6643

@@ -85,6 +62,30 @@ async fn main() {
8562
.unwrap();
8663
}
8764

65+
/// Runs a loop that checks for deadlocks every 10 seconds.
66+
///
67+
/// Note that this requires the `deadlock_detection` parking_lot feature to be
68+
/// enabled, which is only enabled in azalea by default when running in debug
69+
/// mode.
70+
fn deadlock_detection_thread() {
71+
loop {
72+
thread::sleep(Duration::from_secs(10));
73+
let deadlocks = parking_lot::deadlock::check_deadlock();
74+
if deadlocks.is_empty() {
75+
continue;
76+
}
77+
78+
println!("{} deadlocks detected", deadlocks.len());
79+
for (i, threads) in deadlocks.iter().enumerate() {
80+
println!("Deadlock #{i}");
81+
for t in threads {
82+
println!("Thread Id {:#?}", t.thread_id());
83+
println!("{:#?}", t.backtrace());
84+
}
85+
}
86+
}
87+
}
88+
8889
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
8990
pub enum BotTask {
9091
#[default]

0 commit comments

Comments
 (0)