Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Add a deadlock detection thread (#8727)
Browse files Browse the repository at this point in the history
* Add a deadlock detection thread

Expose it under a feature flag:
`cargo build --features "deadlock_detection"`

* Address Nicklas's comments
  • Loading branch information
ordian authored and tomusdrw committed Jun 25, 2018
1 parent 07cf4d0 commit 68e8079
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ evm-debug-tests = ["ethcore/evm-debug-tests"]
slow-blocks = ["ethcore/slow-blocks"]
secretstore = ["ethcore-secretstore"]
final = ["parity-version/final"]
deadlock_detection = ["parking_lot/deadlock_detection"]

[[bin]]
path = "parity/main.rs"
Expand Down
32 changes: 32 additions & 0 deletions parity/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,35 @@ fn print_hash_of(maybe_file: Option<String>) -> Result<String, String> {
}
}


#[cfg(feature = "deadlock_detection")]
fn run_deadlock_detection_thread() {
use std::thread;
use std::time::Duration;
use parking_lot::deadlock;

info!("Starting deadlock detection 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;
}

warn!("{} {} detected", deadlocks.len(), Style::new().bold().paint("deadlock(s)"));
for (i, threads) in deadlocks.iter().enumerate() {
warn!("{} #{}", Style::new().bold().paint("Deadlock"), i);
for t in threads {
warn!("Thread Id {:#?}", t.thread_id());
warn!("{:#?}", t.backtrace());
}
}
}
});
}

enum PostExecutionAction {
Print(String),
Restart(Option<String>),
Expand All @@ -157,6 +186,9 @@ enum PostExecutionAction {
fn execute(command: Execute, can_restart: bool) -> Result<PostExecutionAction, String> {
let logger = setup_log(&command.logger).expect("Logger is initialized only once; qed");

#[cfg(feature = "deadlock_detection")]
run_deadlock_detection_thread();

match command.cmd {
Cmd::Run(run_cmd) => {
let (restart, spec_name) = run::execute(run_cmd, can_restart, logger)?;
Expand Down

0 comments on commit 68e8079

Please sign in to comment.