fix(hfs): drain on SIGTERM as well as Ctrl-C (Phase 0.3) - #907
Open
aacruzgon wants to merge 1 commit into
Open
Conversation
The graceful-shutdown future only waited on Ctrl-C, so a SIGTERM from a process supervisor, container runtime, or a load balancer's rolling deploy killed the server after the grace period with requests in flight and the audit sink unflushed — the normal way an instance in a cluster is stopped. `serve()` now waits on a `shutdown_signal()` that selects over Ctrl-C and, on Unix, SIGTERM, and logs which signal fired; the drain, audit flush and OTLP flush that follow are unchanged. A failed SIGTERM handler install warns and keeps Ctrl-C only; non-Unix builds keep Ctrl-C only. Tests: verified by hand — a running instance answers /health, receives `kill -TERM`, logs `Shutdown signal received … signal="SIGTERM"` and exits within a second. The two-instance smoke's stop step switches to SIGTERM in the next cluster PR so this stays covered in CI.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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
Phase 0.3 of the cluster-capable-state rebuild (discussion #223).
hfsonly ever drained on Ctrl-C; a SIGTERM from a process supervisor, container runtime, or a load balancer's rolling deploy killed it outright after the grace period, with requests in flight and the audit sink unflushed. The graceful-shutdown future now resolves on either signal and logs which one fired.Independent of #905 and #906 (branched from
main; touches onlyserve()'s shutdown future).Changes
crates/hfs/src/main.rs— newshutdown_signal()thatselect!s overtokio::signal::ctrl_c()and, on Unix,SignalKind::terminate();serve()'swith_graceful_shutdownuses it and logssignal="SIGINT"|"SIGTERM". The audit flush and OTLP flush that follow are unchanged. If the SIGTERM handler cannot be installed the server warns and keeps Ctrl-C only. Non-Unix builds keep Ctrl-C only. tokio'sfullfeature already includessignal, so no manifest change.Testing
hfs(sqlite, in-memory), confirmed/health200, sentkill -TERM; the process loggedShutdown signal received, draining connections signal="SIGTERM"and exited within a second. Without this change the same signal terminates the process with no drain and no log line.cargo test -p helios-hfs --no-default-features --features R4,sqlite,postgres— 8 passed (no unit test can send a signal; the T3 cluster-smoke stop step switches tokill -TERMin PR 0.4 and asserts a clean exit).cargo fmt --all; CI-exact clippy clean.Notes
hts,sof-server, andfhirpath-serverhave no graceful shutdown at all (bareaxum::serve); noted as a follow-up, same ~25 lines each.