Removed a couple deadlocks
This commit is contained in:
parent
38c99023ac
commit
adf3eef877
7 changed files with 899 additions and 1 deletions
|
|
@ -543,6 +543,8 @@ impl TorrentState {
|
|||
}
|
||||
PeerState::Queued | PeerState::Dead | PeerState::NotNeeded => {
|
||||
warn!("bug: peer was in a wrong state, ignoring it forever");
|
||||
// Prevent deadlocks.
|
||||
drop(pe);
|
||||
self.peers.drop_peer(handle);
|
||||
return;
|
||||
}
|
||||
|
|
@ -563,6 +565,9 @@ impl TorrentState {
|
|||
pe.value_mut().state = PeerState::Dead;
|
||||
let backoff = pe.value_mut().stats.backoff.next_backoff();
|
||||
|
||||
// Prevent deadlocks.
|
||||
drop(pe);
|
||||
|
||||
if let Some(dur) = backoff {
|
||||
let state = self.clone();
|
||||
spawn(
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ tracing-subscriber = {version = "0.3", features = ["env-filter"]}
|
|||
regex = "1"
|
||||
futures = "0.3"
|
||||
parse_duration = "2"
|
||||
parking_lot = {version = "0.12", features = ["deadlock_detection"]}
|
||||
reqwest = "0.11"
|
||||
serde = {version = "1", features=["derive"]}
|
||||
serde_json = "1"
|
||||
|
|
|
|||
|
|
@ -160,10 +160,35 @@ fn init_logging(opts: &Opts) {
|
|||
.init();
|
||||
}
|
||||
|
||||
fn _start_deadlock_detector_thread() {
|
||||
use parking_lot::deadlock;
|
||||
use std::thread;
|
||||
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
std::process::exit(42);
|
||||
});
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let opts = Opts::parse();
|
||||
|
||||
init_logging(&opts);
|
||||
// start_deadlock_detector_thread();
|
||||
|
||||
let (mut rt_builder, spawner) = match opts.single_thread_runtime {
|
||||
true => (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue