Handle SIGTERM gracefully in server and master - #262
Merged
beinan merged 3 commits intoSep 23, 2026
Merged
Conversation
beinan
approved these changes
Sep 23, 2026
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.
Why
Kubernetes stops a pod by sending
SIGTERM. The server and master previously waited only for Ctrl+C, so a rollout or scale-down could terminate either process before Axum drained active connections. For the server, this also meantstate.shutdown()was never reached to close resident writers cleanly.flowchart LR subgraph before ["Before"] direction TB ctrl_before["Ctrl+C / SIGINT"] --> graceful_before["Axum graceful shutdown"] term_before["SIGTERM"] --> exit_before["Process exits immediately"] end subgraph after ["After"] direction TB ctrl_after["Ctrl+C / SIGINT"] --> select_after["tokio::select!"] term_after["SIGTERM"] --> select_after select_after --> graceful_after["Axum graceful shutdown"] graceful_after --> drain_after["Drain active connections"] drain_after --> close_after["state.shutdown(): close writers"] endFor example, during a Kubernetes rolling deployment:
SIGTERMto the old pod.What changed
SIGINT/Ctrl+C orSIGTERMon Unix in both binaries.Popen.terminate()sendsSIGTERMon POSIX.Testing