Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shutdown. #822

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}
}
Loading