From 5673983e7de82678bf1ad30d67c90214356b6e98 Mon Sep 17 00:00:00 2001 From: yukang Date: Wed, 2 Aug 2023 14:38:14 +0800 Subject: [PATCH] node start will not panic when child process crashed --- test/Cargo.toml | 1 + test/src/main.rs | 3 +-- test/src/node.rs | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/Cargo.toml b/test/Cargo.toml index 3dc3649d0e..2f31f4dd68 100644 --- a/test/Cargo.toml +++ b/test/Cargo.toml @@ -38,6 +38,7 @@ lazy_static = "1.4.0" byteorder = "1.3.1" jsonrpc-core = "18.0" ctrlc = { version = "3.1", features = ["termination"] } +log = "0.4" [target.'cfg(not(target_os="windows"))'.dependencies] nix = { version = "0.24.0", default-features = false, features = ["signal"] } diff --git a/test/src/main.rs b/test/src/main.rs index f650e7ab35..02e09c809b 100644 --- a/test/src/main.rs +++ b/test/src/main.rs @@ -135,8 +135,7 @@ fn main() { for name in cloned_running_names.lock().iter() { warn!("spec {} is still not finished", name); } - // sleep 1 second to wait for the log flush - std::thread::sleep(Duration::from_secs(1)); + log::logger().flush(); std::process::exit(1); }) .expect("Error setting Ctrl-C handler"); diff --git a/test/src/node.rs b/test/src/node.rs index 50a8c8f21d..168370bcaa 100644 --- a/test/src/node.rs +++ b/test/src/node.rs @@ -22,7 +22,7 @@ use std::collections::HashSet; use std::convert::Into; use std::fs; use std::path::PathBuf; -use std::process::{self, Child, Command, Stdio}; +use std::process::{Child, Command, Stdio}; use std::thread::sleep; use std::time::{Duration, Instant}; @@ -609,7 +609,8 @@ impl Node { status, self.log_path().display() ); - process::exit(status.code().unwrap()); + // parent process will exit + return; } Err(error) => { error!( @@ -617,7 +618,7 @@ impl Node { error, self.log_path().display() ); - process::exit(255); + return; } } };