Skip to content

Commit b62d682

Browse files
committed
On detecting a deadlock, we are shutting down the Node Software now if the feature "shutdown-on-deadlock" is defined, and is activated as a default feature for now.
Shutdowns are now timed to take a maximum of 60 seconds, instead of 300 seconds. DMDcoin#231 Code Infrastructure changes: ShutdownManager is now hosted as an Arc.
1 parent 492d598 commit b62d682

File tree

7 files changed

+31
-16
lines changed

7 files changed

+31
-16
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ lazy_static = "1.2.0"
9999
winapi = { version = "0.3.4", features = ["winsock2", "winuser", "shellapi"] }
100100

101101
[features]
102-
default = ["accounts"]
102+
default = ["shutdown-on-deadlock", "accounts"]
103103
accounts = ["ethcore-accounts", "parity-rpc/accounts"]
104104
miner-debug = ["ethcore/miner-debug"]
105105
json-tests = ["ethcore/json-tests"]
@@ -118,6 +118,7 @@ deadlock_detection = ["parking_lot/deadlock_detection"]
118118
# and `massif-visualizer` for visualization
119119
memory_profiling = []
120120
secretstore = []
121+
shutdown-on-deadlock = ["deadlock_detection"]
121122

122123
[lib]
123124
path = "bin/oe/lib.rs"

bin/oe/blockchain.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result<(), String> {
214214
// TODO [ToDr] don't use test miner here
215215
// (actually don't require miner at all)
216216
Arc::new(Miner::new_for_tests(&spec, None)),
217-
ShutdownManager::null(),
217+
Arc::new(ShutdownManager::null()),
218218
)
219219
.map_err(|e| format!("Client service error: {:?}", e))?;
220220

@@ -282,7 +282,7 @@ fn start_client(
282282
require_fat_db: bool,
283283
max_round_blocks_to_import: usize,
284284
shutdown_on_missing_block_import: Option<u64>,
285-
shutdown: ShutdownManager,
285+
shutdown: Arc<ShutdownManager>,
286286
) -> Result<ClientService, String> {
287287
// load spec file
288288
let spec = spec.spec(&dirs.cache)?;
@@ -376,7 +376,7 @@ fn execute_export(cmd: ExportBlockchain) -> Result<(), String> {
376376
false,
377377
cmd.max_round_blocks_to_import,
378378
None,
379-
ShutdownManager::null(),
379+
Arc::new(ShutdownManager::null()),
380380
)?;
381381
let client = service.client();
382382

@@ -407,7 +407,7 @@ fn execute_export_state(cmd: ExportState) -> Result<(), String> {
407407
true,
408408
cmd.max_round_blocks_to_import,
409409
None,
410-
ShutdownManager::null(),
410+
Arc::new(ShutdownManager::null()),
411411
)?;
412412

413413
let client = service.client();
@@ -527,7 +527,7 @@ fn execute_reset(cmd: ResetBlockchain) -> Result<(), String> {
527527
false,
528528
0,
529529
None,
530-
ShutdownManager::null(),
530+
Arc::new(ShutdownManager::null()),
531531
)?;
532532

533533
let client = service.client();

bin/oe/lib.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,18 @@ fn print_hash_of(maybe_file: Option<String>) -> Result<String, String> {
146146
}
147147

148148
#[cfg(feature = "deadlock_detection")]
149-
fn run_deadlock_detection_thread() {
149+
#[cfg(feature = "shutdown-on-deadlock")]
150+
fn on_deadlock_detected(shutdown: &Arc<ShutdownManager>) {
151+
warn!("Deadlock detected, trying to shutdown the node software");
152+
shutdown.demand_shutdown();
153+
}
154+
155+
#[cfg(feature = "deadlock_detection")]
156+
#[cfg(not(feature = "shutdown-on-deadlock"))]
157+
fn on_deadlock_detected(_: &Arc<ShutdownManager>) {}
158+
159+
#[cfg(feature = "deadlock_detection")]
160+
fn run_deadlock_detection_thread(shutdown: Arc<ShutdownManager>) {
150161
use ansi_term::Style;
151162
use parking_lot::deadlock;
152163
use std::{thread, time::Duration};
@@ -176,6 +187,7 @@ fn run_deadlock_detection_thread() {
176187
warn!("{:#?}", t.backtrace());
177188
}
178189
}
190+
on_deadlock_detected(&shutdown);
179191
}
180192
});
181193

@@ -206,12 +218,14 @@ fn execute(
206218
logger: Arc<RotatingLogger>,
207219
shutdown: ShutdownManager,
208220
) -> Result<ExecutionAction, String> {
221+
let shutdown_arc = Arc::new(shutdown);
222+
209223
#[cfg(feature = "deadlock_detection")]
210-
run_deadlock_detection_thread();
224+
run_deadlock_detection_thread(shutdown_arc.clone());
211225

212226
match command.cmd {
213227
Cmd::Run(run_cmd) => {
214-
let outcome = run::execute(run_cmd, logger, shutdown)?;
228+
let outcome = run::execute(run_cmd, logger, shutdown_arc)?;
215229
Ok(ExecutionAction::Running(outcome))
216230
}
217231
Cmd::Version => Ok(ExecutionAction::Instant(Some(Args::print_version()))),

bin/oe/run.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl ChainSyncing for SyncProviderWrapper {
177177
pub fn execute(
178178
cmd: RunCmd,
179179
logger: Arc<RotatingLogger>,
180-
shutdown: ShutdownManager,
180+
shutdown: Arc<ShutdownManager>,
181181
) -> Result<RunningClient, String> {
182182
// load spec
183183
let spec = cmd.spec.spec(&cmd.dirs.cache)?;
@@ -755,8 +755,8 @@ fn print_running_environment(data_dir: &str, dirs: &Directories, db_dirs: &Datab
755755

756756
fn wait_for_drop<T>(w: Weak<T>) {
757757
const SLEEP_DURATION: Duration = Duration::from_secs(1);
758-
const WARN_TIMEOUT: Duration = Duration::from_secs(60);
759-
const MAX_TIMEOUT: Duration = Duration::from_secs(300);
758+
const WARN_TIMEOUT: Duration = Duration::from_secs(30);
759+
const MAX_TIMEOUT: Duration = Duration::from_secs(60);
760760

761761
let instant = Instant::now();
762762
let mut warned = false;

bin/oe/snapshot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl SnapshotCommand {
241241
// TODO [ToDr] don't use test miner here
242242
// (actually don't require miner at all)
243243
Arc::new(Miner::new_for_tests(&spec, None)),
244-
ShutdownManager::null(),
244+
Arc::new(ShutdownManager::null()),
245245
)
246246
.map_err(|e| format!("Client service error: {:?}", e))?;
247247

crates/ethcore/service/src/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl ClientService {
5858
restoration_db_handler: Box<dyn BlockChainDBHandler>,
5959
_ipc_path: &Path,
6060
miner: Arc<Miner>,
61-
shutdown: ShutdownManager,
61+
shutdown: Arc<ShutdownManager>,
6262
) -> Result<ClientService, Error> {
6363
let io_service = IoService::<ClientIoMessage>::start("Client", 4)?;
6464

crates/ethcore/src/client/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ pub struct Client {
304304

305305
importer: Importer,
306306

307-
shutdown: ShutdownManager,
307+
shutdown: Arc<ShutdownManager>,
308308

309309
statistics: ClientStatistics,
310310
}
@@ -994,7 +994,7 @@ impl Client {
994994
db: Arc<dyn BlockChainDB>,
995995
miner: Arc<Miner>,
996996
message_channel: IoChannel<ClientIoMessage>,
997-
shutdown: ShutdownManager,
997+
shutdown: Arc<ShutdownManager>,
998998
) -> Result<Arc<Client>, crate::error::Error> {
999999
let trie_spec = match config.fat_db {
10001000
true => TrieSpec::Fat,

0 commit comments

Comments
 (0)