handle exit and avoid threads hanging (#137)

* barrier on starting network

* handle exit better

* give consensus service its own internal exit signal

* update comment

* remove stop_notifications and fix build
This commit is contained in:
Robert Habermeier
2018-04-18 13:59:46 +02:00
committed by Arkadiy Paronyan
parent e253a4cb9f
commit b6132800b7
8 changed files with 128 additions and 62 deletions
+9 -5
View File
@@ -68,6 +68,15 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
T: Into<std::ffi::OsString> + Clone,
{
let mut core = reactor::Core::new().expect("tokio::Core could not be created");
let exit = {
// can't use signal directly here because CtrlC takes only `Fn`.
let (exit_send, exit) = mpsc::channel(1);
ctrlc::CtrlC::set_handler(move || {
exit_send.clone().send(()).wait().expect("Error sending exit notification");
});
exit
};
let yaml = load_yaml!("./cli.yml");
let matches = match clap::App::from_yaml(yaml).version(crate_version!()).get_matches_from_safe(args) {
@@ -140,11 +149,6 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
informant::start(&service, core.handle());
let (exit_send, exit) = mpsc::channel(1);
ctrlc::CtrlC::set_handler(move || {
exit_send.clone().send(()).wait().expect("Error sending exit notification");
});
let _rpc_servers = {
let http_address = parse_address("127.0.0.1:9933", "rpc-port", &matches)?;
let ws_address = parse_address("127.0.0.1:9944", "ws-port", &matches)?;