Removed a couple deadlocks

This commit is contained in:
Igor Katson 2023-11-19 16:25:59 +00:00
parent 38c99023ac
commit adf3eef877
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
7 changed files with 899 additions and 1 deletions

View file

@ -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(

View file

@ -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"

View file

@ -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 => (