Skip to content

Commit 05af3ac

Browse files
Seulgi Kimsgkim126
authored andcommitted
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.
1 parent 0195fe7 commit 05af3ac

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

codechain/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern crate serde_json;
3030
extern crate app_dirs;
3131
extern crate codechain_core as ccore;
3232
extern crate codechain_discovery as cdiscovery;
33+
extern crate codechain_finally as cfinally;
3334
extern crate codechain_key as ckey;
3435
extern crate codechain_keystore as ckeystore;
3536
#[macro_use]

codechain/run_node.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17+
use std::env;
1718
use std::fs;
1819
use std::path::Path;
1920
use std::sync::Arc;
20-
use std::time::{SystemTime, UNIX_EPOCH};
21+
use std::time::{Duration, SystemTime, UNIX_EPOCH};
2122

2223
use ccore::{
2324
AccountProvider, Client, ClientService, EngineType, Miner, MinerService, Scheme, ShardValidator, Stratum,
2425
StratumConfig, StratumError,
2526
};
2627
use cdiscovery::{KademliaConfig, KademliaExtension, UnstructuredConfig, UnstructuredExtension};
28+
use cfinally::finally;
2729
use ckeystore::accounts_dir::RootDiskDirectory;
2830
use ckeystore::KeyStore;
2931
use clap::ArgMatches;
@@ -170,6 +172,17 @@ pub fn run_node(matches: ArgMatches) -> Result<(), String> {
170172
let _event_loop = EventLoop::spawn();
171173
let config = load_config(&matches)?;
172174

175+
// FIXME: It is the hotfix for #348.
176+
// Remove the below code if you find the proper way to solve #348.
177+
let _wait = finally(|| {
178+
const DEFAULT: u64 = 1;
179+
let wait_before_shutdown = env::var_os("WAIT_BEFORE_SHUTDOWN")
180+
.and_then(|sec| sec.into_string().ok())
181+
.and_then(|sec| sec.parse().ok())
182+
.unwrap_or(DEFAULT);
183+
::std::thread::sleep(Duration::from_secs(wait_before_shutdown));
184+
});
185+
173186
let scheme = config.operating.chain.scheme()?;
174187

175188
let instance_id = config.operating.instance_id.unwrap_or(

0 commit comments

Comments
 (0)