BM-2707: fix(broker): stop supervisor respawning tasks during shutdown, add force shutdown - #1791
Open
jonastheis wants to merge 1 commit into
Open
BM-2707: fix(broker): stop supervisor respawning tasks during shutdown, add force shutdown#1791jonastheis wants to merge 1 commit into
jonastheis wants to merge 1 commit into
Conversation
…rce shutdown - Supervisor now checks cancel_token.is_cancelled() before spawning a replacement on Recover errors, stopping the restart cascade visible in logs after CTRL+C - First shutdown signal now hints "Press CTRL+C again to force immediate shutdown" - Second CTRL+C during shutdown immediately cancels critical tasks instead of waiting for the grace period
jonastheis
requested review from
a team,
Wollac,
austinabell,
capossele,
ec2,
nahoc,
unizarr,
willemolding and
zeroecco
as code owners
March 25, 2026 05:30
austinabell
approved these changes
Mar 25, 2026
austinabell
left a comment
Contributor
There was a problem hiding this comment.
sigkill was basically the pattern to use if you wanted to force shutdown. Was intentional to avoid shutting down with two sigint signals, to avoid the case where an in progress order wouldn't complete. Did you verify that docker compose doesn't send multiple sigints when shutting down? Risk is that accidentally or with some other infra setup, the broker would accidentally be shut down mid order and be slashed, but I think this is fine if at least our default flow doesn't do this.
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.
Summary
Fixes two shutdown UX issues in the broker:
Supervisor restart loop during shutdown — after CTRL+C, the task supervisor would keep respawning tasks (ChainMonitorV2, offchain market monitor) on recoverable errors instead of exiting cleanly. This happened because
Supervisor::spawn()entered theRecoverarm with no check for whether the cancellation token was already set. Now it checkscancel_token.is_cancelled()first and breaks the loop instead of spawning a replacement.No way to force immediate shutdown — the graceful shutdown can take up to 2 hours waiting for in-progress orders to drain. A second CTRL+C during shutdown now cancels the critical token immediately. The first shutdown message also hints at this.
Changes
crates/broker/src/task.rs— addcancel_token.is_cancelled()check at the top of theRecoverarm inSupervisor::spawn()crates/broker/src/lib.rs— update first-signal messages to hint about force shutdown; wrap Phase 1 + Phase 2 intokio::select!that races against a secondctrl_c()