Skip to content

Shutdown on unexpected task exit#136

Open
ReinierMaas wants to merge 1 commit into
masterfrom
reinier/shutdown-opsqueue-on-unexpected-task-exit
Open

Shutdown on unexpected task exit#136
ReinierMaas wants to merge 1 commit into
masterfrom
reinier/shutdown-opsqueue-on-unexpected-task-exit

Conversation

@ReinierMaas

Copy link
Copy Markdown
Contributor

I discovered Opsqueue limping along when the server shutdown unexpectedly. After my initial investigation I found out that this was due tot the moro_local scope not shutting down when one of the managed spawned tasks exited. I added a tokio::select! on all the spawn handles to initiate a complete shutdown when this happens again.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Opsqueue application entrypoint to trigger a full shutdown when any of the long-running tasks spawned inside the moro_local scope exits unexpectedly, addressing cases where the server stops but the process keeps limping along.

Changes:

  • Capture scope.spawn(...) handles for the checkpoint, server, cleanup, prometheus metrics, and watchdog tasks.
  • Add a tokio::select! that initiates shutdown when any spawned task completes or when Ctrl+C is received.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread opsqueue/app/main.rs
Comment on lines +83 to +105
tokio::select! {
_ = checkpoint_handle => {
tracing::error!("Checkpointing task exited unexpectedly");
},
_ = server_handle => {
tracing::error!("Server task exited unexpectedly");
},
_ = cleanup_handle => {
tracing::error!("Cleanup task exited unexpectedly");
},
_ = prometheus_handle => {
tracing::error!("Prometheus metrics calculation task exited unexpectedly");
},
_ = watchdog_handle => {
tracing::error!("Watchdog task exited unexpectedly");
},
res = tokio::signal::ctrl_c() => {
match res {
Ok(_) => tracing::warn!("Received Ctrl-C signal"),
Err(ref err) => tracing::error!(error = err as &dyn Error, "Error while waiting for Ctrl-C signal"),
};
},
};
Comment thread opsqueue/app/main.rs
Comment on lines 8 to 12
use std::{
error::Error,
sync::{atomic::AtomicBool, Arc},
time::Duration,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants