forked from nervosnetwork/ckb
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: experimental deadlock detection
- Loading branch information
1 parent
b34a0c0
commit f55cec5
Showing
7 changed files
with
82 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use ckb_util::{parking_lot::deadlock, Condvar, Mutex}; | ||
use log::warn; | ||
use std::sync::Arc; | ||
use std::thread; | ||
use std::time::Duration; | ||
|
||
pub fn wait_for_exit() { | ||
let exit = Arc::new((Mutex::new(()), Condvar::new())); | ||
|
||
// Handle possible exits | ||
let e = Arc::<(Mutex<()>, Condvar)>::clone(&exit); | ||
let _ = ctrlc::set_handler(move || { | ||
e.1.notify_all(); | ||
}); | ||
|
||
// Wait for signal | ||
let mut l = exit.0.lock(); | ||
exit.1.wait(&mut l); | ||
} | ||
|
||
pub fn deadlock_detection() { | ||
thread::spawn(move || loop { | ||
thread::sleep(Duration::from_secs(10)); | ||
let deadlocks = deadlock::check_deadlock(); | ||
if deadlocks.is_empty() { | ||
continue; | ||
} | ||
|
||
warn!("{} deadlocks detected", deadlocks.len()); | ||
for (i, threads) in deadlocks.iter().enumerate() { | ||
warn!("Deadlock #{}", i); | ||
for t in threads { | ||
warn!("Thread Id {:#?}", t.thread_id()); | ||
warn!("{:#?}", t.backtrace()); | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
mod helper; | ||
mod setup; | ||
mod subcommand; | ||
mod system; | ||
|
||
use setup::{cli, ExitCode, Setup}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters