Skip to content

Commit

Permalink
Speed up Zebra shutdown: skip waiting for the tokio runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Nov 23, 2021
1 parent 70e647c commit 26db90a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions zebrad/src/components/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,22 @@ pub(crate) trait RuntimeRun {
impl RuntimeRun for Runtime {
fn run(&mut self, fut: impl Future<Output = Result<(), Report>>) {
let result = self.block_on(async move {
// If the run task and shutdown are both ready, select! chooses
// one of them at random.
// Always poll the shutdown future first.
//
// Otherwise, a busy Zebra instance could starve the shutdown future,
// and delay shutting down.
tokio::select! {
result = fut => result,
biased;
_ = shutdown() => Ok(()),
result = fut => result,
}
});

match result {
Ok(()) => {}
Ok(()) => {
// Don't wait for the runtime to shut down all the tasks.
app_writer().shutdown(Shutdown::Graceful);
}
Err(e) => {
eprintln!("Error: {:?}", e);
app_writer().shutdown(Shutdown::Forced);
Expand Down

0 comments on commit 26db90a

Please sign in to comment.