Skip to content

Commit

Permalink
Correctly shut down the progress bar, and shut it down on an interrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Feb 27, 2023
1 parent 9ff3e96 commit 049edde
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion zebrad/src/components/sync/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ pub async fn show_block_chain_progress(

// Send progress reports for block height
#[cfg(feature = "progress-bar")]
{
if matches!(howudoin::cancelled(), Some(true)) {
return;
} else {
block_bar.set_pos(current_height.0);
block_bar.set_len(u64::from(estimated_height.0));
block_bar.desc(network_upgrade.to_string());
Expand Down
8 changes: 8 additions & 0 deletions zebrad/src/components/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ mod imp {
.expect("Failed to register signal handler")
.recv()
.await;

zebra_chain::shutdown::set_shutting_down();

#[cfg(feature = "progress-bar")]
howudoin::disable();

info!(
// use target to remove 'imp' from output
target: "zebrad::signal",
Expand All @@ -131,8 +135,12 @@ mod imp {
tokio::signal::ctrl_c()
.await
.expect("listening for ctrl-c signal should never fail");

zebra_chain::shutdown::set_shutting_down();

#[cfg(feature = "progress-bar")]
howudoin::disable();

info!(
// use target to remove 'imp' from output
target: "zebrad::signal",
Expand Down
9 changes: 8 additions & 1 deletion zebrad/src/components/tracing/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,15 @@ impl<A: abscissa_core::Application> Component<A> for Tracing {
}

#[cfg(feature = "progress-bar")]
howudoin::cancel();
howudoin::disable();

Ok(())
}
}

impl Drop for Tracing {
fn drop(&mut self) {
#[cfg(feature = "progress-bar")]
howudoin::disable();
}
}

0 comments on commit 049edde

Please sign in to comment.