Skip to content

Commit

Permalink
Fix shutdown. (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
piohei authored Nov 27, 2024
1 parent 9af7b2c commit 2c57948
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ async fn sequencer_app(args: Args) -> anyhow::Result<()> {
tracing::info!("Shutting down");
shutdown.shutdown();

shutdown.await_shutdown_complete().await;

Ok(())
}

Expand Down
1 change: 0 additions & 1 deletion src/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ impl Shutdown {
_ = self.await_shutdown_complete() => {
let elapsed = start.elapsed();
info!("shutdown channel closed, gracefully shut down in {:?}", elapsed);
std::process::exit(0);
},
_ = tokio::time::sleep(timeout) => {
error!("shutdown monitor timed out");
Expand Down
10 changes: 8 additions & 2 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,13 @@ mod tests {
tokio::time::sleep(Duration::from_millis(50)).await;
assert!(handle.is_finished(), "Task should be finished");

tokio::time::sleep(Duration::from_millis(100)).await;
panic!("The process should have exited already");
select! {
_ = shutdown.await_shutdown_complete() => {
Ok(())
},
_ = tokio::time::sleep(Duration::from_millis(100)) => {
panic!("The process should have exited already");
}
}
}
}
11 changes: 9 additions & 2 deletions tests/graceful_shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mod common;

use common::prelude::*;
use tokio::select;

const IDLE_TIME: u64 = 5;

Expand Down Expand Up @@ -64,6 +65,12 @@ async fn graceful_shutdown(offchain_mode_enabled: bool) -> anyhow::Result<()> {
tokio::time::sleep(Duration::from_secs(IDLE_TIME)).await;
shutdown.shutdown();

tokio::time::sleep(Duration::from_secs(5)).await;
panic!("error: process took longer than 5 seconds to shutdown");
select! {
_ = shutdown.await_shutdown_complete() => {
Ok(())
},
_ = tokio::time::sleep(Duration::from_secs(5)) => {
panic!("error: process took longer than 5 seconds to shutdown");
}
}
}

0 comments on commit 2c57948

Please sign in to comment.