From d924beb6a6508bd887fa41d7e7a37d5d0b1ba62a Mon Sep 17 00:00:00 2001 From: Stan Bondi Date: Wed, 25 Aug 2021 13:01:19 +0400 Subject: [PATCH] fix: exit command and free up tokio thread (#3235) Description --- Exit command didn't exit the cli loop. Rustyline was holding up a tokio thread - used a blocking thread instead Motivation and Context --- Bug How Has This Been Tested? --- Manually on base node --- Cargo.lock | 2 +- applications/tari_base_node/src/main.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9dfd279170..188850e8e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5060,7 +5060,7 @@ dependencies = [ [[package]] name = "tari_wallet_ffi" -version = "0.17.3" +version = "0.17.4" dependencies = [ "chrono", "env_logger 0.7.1", diff --git a/applications/tari_base_node/src/main.rs b/applications/tari_base_node/src/main.rs index 5b51179c4a..bd66eb2544 100644 --- a/applications/tari_base_node/src/main.rs +++ b/applications/tari_base_node/src/main.rs @@ -264,7 +264,7 @@ async fn run_grpc( } async fn read_command(mut rustyline: Editor) -> Result<(String, Editor), String> { - task::spawn(async { + task::spawn_blocking(|| { let readline = rustyline.readline(">> "); match readline { @@ -330,9 +330,11 @@ async fn cli_loop(parser: Parser, mut shutdown: Shutdown) { match res { Ok((line, mut rustyline)) => { if let Some(p) = rustyline.helper_mut().as_deref_mut() { - p.handle_command(line.as_str(), &mut shutdown) + p.handle_command(line.as_str(), &mut shutdown); + } + if !shutdown.is_triggered() { + read_command_fut.set(read_command(rustyline).fuse()); } - read_command_fut.set(read_command(rustyline).fuse()); }, Err(err) => { // This happens when the node is shutting down.