From eabb8362b4f5ded8116f8c99b58d0185f96dcdcc Mon Sep 17 00:00:00 2001 From: Seulgi Kim Date: Thu, 16 Aug 2018 17:34:53 +0900 Subject: [PATCH] Wait before shutdown to avoid the crash This patch is the hotfix for #348. I can't find the exact reason for the SIGINT yet, but this patch fixes the crash. --- codechain/main.rs | 1 + codechain/run_node.rs | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/codechain/main.rs b/codechain/main.rs index d525f75e6e..281242139c 100644 --- a/codechain/main.rs +++ b/codechain/main.rs @@ -30,6 +30,7 @@ extern crate serde_json; extern crate app_dirs; extern crate codechain_core as ccore; extern crate codechain_discovery as cdiscovery; +extern crate codechain_finally as cfinally; extern crate codechain_key as ckey; extern crate codechain_keystore as ckeystore; #[macro_use] diff --git a/codechain/run_node.rs b/codechain/run_node.rs index 8f1d9a36cb..5cc27b2d51 100644 --- a/codechain/run_node.rs +++ b/codechain/run_node.rs @@ -14,16 +14,18 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +use std::env; use std::fs; use std::path::Path; use std::sync::Arc; -use std::time::{SystemTime, UNIX_EPOCH}; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; use ccore::{ AccountProvider, Client, ClientService, EngineType, Miner, MinerService, Scheme, ShardValidator, Stratum, StratumConfig, StratumError, }; use cdiscovery::{KademliaConfig, KademliaExtension, UnstructuredConfig, UnstructuredExtension}; +use cfinally::finally; use ckeystore::accounts_dir::RootDiskDirectory; use ckeystore::KeyStore; use clap::ArgMatches; @@ -170,6 +172,17 @@ pub fn run_node(matches: ArgMatches) -> Result<(), String> { let _event_loop = EventLoop::spawn(); let config = load_config(&matches)?; + // FIXME: It is the hotfix for #348. + // Remove the below code if you find the proper way to solve #348. + let _wait = finally(|| { + const DEFAULT: u64 = 1; + let wait_before_shutdown = env::var_os("WAIT_BEFORE_SHUTDOWN") + .and_then(|sec| sec.into_string().ok()) + .and_then(|sec| sec.parse().ok()) + .unwrap_or(DEFAULT); + ::std::thread::sleep(Duration::from_secs(wait_before_shutdown)); + }); + let scheme = config.operating.chain.scheme()?; let instance_id = config.operating.instance_id.unwrap_or(