Shutdown on unexpected task exit#136
Merged
OpsBotPrime merged 2 commits intoJul 16, 2026
Merged
Conversation
There was a problem hiding this comment.
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 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"), | ||
| }; | ||
| }, | ||
| }; |
Contributor
Author
There was a problem hiding this comment.
These are all Future<Output = ()>, nothing to see here...
Qqwy
approved these changes
Jul 16, 2026
Qqwy
left a comment
Contributor
There was a problem hiding this comment.
This PR does what it says on the tin. Thank you for the improvement! 👍
Contributor
Author
|
@OpsBotPrime merge! |
Approved-by: ReinierMaas Priority: Normal Auto-deploy: false
Contributor
|
Rebased as a16afed, waiting for CI … |
Contributor
|
CI job 🟡 started. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I discovered Opsqueue limping along when the server shutdown unexpectedly. After my initial investigation I found out that this was due tot the
moro_localscope not shutting down when one of the managed spawned tasks exited. I added atokio::select!on all the spawn handles to initiate a complete shutdown when this happens again.