From e8374433b46525d5ebdd5a2209ea494bba9b9962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Tue, 22 Jan 2019 18:53:13 +0000 Subject: [PATCH] cli: fix node shutdown (#100) --- cli/src/lib.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index cf1387b5a2b29..d72ccf3b5d87f 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -115,8 +115,8 @@ pub fn run(args: I, worker: W, version: cli::VersionInfo) -> error::Res let mut runtime = Runtime::new()?; let executor = runtime.executor(); match config.roles == service::Roles::LIGHT { - true => run_until_exit(&mut runtime, Factory::new_light(config, executor)?, worker)?, - false => run_until_exit(&mut runtime, Factory::new_full(config, executor)?, worker)?, + true => run_until_exit(runtime, Factory::new_light(config, executor)?, worker)?, + false => run_until_exit(runtime, Factory::new_full(config, executor)?, worker)?, } } } @@ -124,7 +124,7 @@ pub fn run(args: I, worker: W, version: cli::VersionInfo) -> error::Res } fn run_until_exit( - runtime: &mut Runtime, + mut runtime: Runtime, service: T, worker: W, ) -> error::Result<()> @@ -141,5 +141,14 @@ fn run_until_exit( let _ = runtime.block_on(worker.work(&*service)); exit_send.fire(); + + // we eagerly drop the service so that the internal exit future is fired, + // but we need to keep holding a reference to the global telemetry guard + let _telemetry = service.telemetry(); + drop(service); + + // TODO [andre]: timeout this future (https://github.com/paritytech/substrate/issues/1318) + let _ = runtime.shutdown_on_idle().wait(); + Ok(()) }