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

Add a deadlock detection thread #8727

Merged
merged 2 commits into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -106,6 +106,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"]

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

fn run_deadlock_detection_thread() {
#[cfg(feature = "deadlock_detection")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason of putting this conditional compilation flag inside the function rather than outside?

{ // only for #[cfg]
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;
}
Copy link
Collaborator

@niklasad1 niklasad1 May 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grumble on this if statement because deadlock iterator will handle this case but I guess it is ok if you want to print the number of deadlocks!

No big deal for me I just want the code to be as simple as possible!


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grumble on this if statement because deadlock iterator will handle this case but I guess it is ok if you want to print the number of deadlocks!

No big deal for me I just want the code to be as simple as possible!

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());
}
}
}
});
}
}


/// Action that Parity performed when running `start`.
pub enum ExecutionAction {
/// The execution didn't require starting a node, and thus has finished.
Expand All @@ -161,6 +192,8 @@ fn execute<Cr, Rr>(command: Execute, on_client_rq: Cr, on_updater_rq: Rr) -> Res
// they want
let logger = setup_log(&command.logger).expect("Logger is initialized only once; qed");

run_deadlock_detection_thread();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be more verbose to have a compilation flag here

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


match command.cmd {
Cmd::Run(run_cmd) => {
if run_cmd.ui_conf.enabled && !run_cmd.ui_conf.info_page_only {
Expand Down