Skip to content

Commit

Permalink
Fix base node shutdown
Browse files Browse the repository at this point in the history
Fixed the base node shutdown on Ubuntu whereas pressing Ctrl-C multiple times rendered the
command line interface in an undefined state. This was not issue on Windows.

Note: The change to 'base_layer\core\src\base_node\tari_pulse_service\mod.rs' is just to
enable testing (get rid of the repeated command-line spam), and will be fixed in #6696.
  • Loading branch information
hansieodendaal committed Nov 21, 2024
1 parent 0610bcc commit fbf6099
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
29 changes: 25 additions & 4 deletions applications/minotari_node/src/commands/cli_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use tokio::{signal, time};
use crate::{
commands::{
cli,
command::{CommandContext, WatchCommand},
command::{Args, CommandContext, WatchCommand},
parser::Parser,
reader::CommandReader,
},
Expand Down Expand Up @@ -87,7 +87,9 @@ impl CliLoop {
} else {
while !self.done {
self.watch_loop().await;
self.execute_command().await;
if !self.done {
self.execute_command().await;
}
}
}
}
Expand Down Expand Up @@ -129,12 +131,19 @@ impl CliLoop {
println!("Wrong command to watch `{}`. Failed with: {}", line, err);
} else {
let mut events = EventStream::new();
loop {
while !self.done {
let interval = time::sleep(interval);
tokio::select! {
_ = interval => {
if let Err(err) = self.context.handle_command_str(line).await {
println!("Watched command `{}` failed: {}", line, err);
} else {
let args: Result<Args, _> = line.parse();
if let Ok(command) = args {
if command.is_quit() {
self.done = true;
}
}
}
continue;
},
Expand All @@ -158,7 +167,9 @@ impl CliLoop {
}
}
}
crossterm::execute!(io::stdout(), cursor::MoveToNextLine(1)).ok();
if !self.done {
crossterm::execute!(io::stdout(), cursor::MoveToNextLine(1)).ok();
}
}
terminal::disable_raw_mode().ok();
}
Expand All @@ -183,6 +194,13 @@ impl CliLoop {
_ = interval => {
if let Err(err) = self.context.handle_command_str(line).await {
println!("Watched command `{}` failed: {}", line, err);
} else {
let args: Result<Args, _> = line.parse();
if let Ok(command) = args {
if command.is_quit() {
self.done = true;
}
}
}
continue;
},
Expand Down Expand Up @@ -242,6 +260,9 @@ impl CliLoop {
} else {
self.done = true;
}
if self.done && !self.shutdown_signal.is_triggered() {
self.context.shutdown.trigger();
}
},
_ = self.shutdown_signal.wait() => {
self.done = true;
Expand Down
6 changes: 6 additions & 0 deletions applications/minotari_node/src/commands/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ pub struct Args {
pub command: Command,
}

impl Args {
pub fn is_quit(&self) -> bool {
matches!(self.command, Command::Quit(_) | Command::Exit(_))
}
}

#[derive(Debug, Subcommand, EnumVariantNames)]
#[strum(serialize_all = "kebab-case")]
pub enum Command {
Expand Down
3 changes: 2 additions & 1 deletion applications/minotari_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ pub struct BaseNodeConfig {
pub state_machine: BaseNodeStateMachineConfig,
/// Obscure GRPC error responses
pub report_grpc_error: bool,
// Interval to check if the base node is still in sync with the network
/// Interval to check if the base node is still in sync with the network
#[serde(with = "serializers::seconds")]
pub tari_pulse_interval: Duration,
}

Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/base_node/tari_pulse_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ impl TariPulseService {
let mut interval = time::interval(self.config.check_interval);
let mut interval_failed = time::interval(Duration::from_millis(100));
loop {
interval.tick().await;
let passed_checkpoints = match self.passed_checkpoints(&mut base_node_service).await {
Ok(passed) => passed,
Err(err) => {
Expand All @@ -130,7 +131,6 @@ impl TariPulseService {
notify_passed_checkpoints
.send(!passed_checkpoints)
.expect("Channel should be open");
interval.tick().await;
}
}

Expand Down

0 comments on commit fbf6099

Please sign in to comment.