-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add a deadlock detection thread #8727
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,37 @@ fn print_hash_of(maybe_file: Option<String>) -> Result<String, String> { | |
} | ||
} | ||
|
||
fn run_deadlock_detection_thread() { | ||
#[cfg(feature = "deadlock_detection")] | ||
{ // 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; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Grumble on this No big deal for me I just want the code to be as simple as possible! |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
There was a problem hiding this comment.
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?