Repository navigation
Description
Parent EPIC: #1488 (SI-21, roadmap row 21).
Goal
On a normal shutdown request, mark the tracker as not ready before components begin draining, so that /health_check returns HTTP 503 for the whole drain and Kubernetes readiness probes and readiness-aware load balancers stop routing new traffic to this instance. Already accepted connections continue through each component's own graceful shutdown policy. This task changes readiness state and the health-check stop order only; it adds no timer and no separate time budget inside the process deadline P.
Measured baseline
On the real binary, with SIGTERM and SIGINT sent to the exact PID while a held request kept a drain open for about 5 seconds, the health-check server stopped accepting at once: new connections got Connection refused (SIGTERM) or Connection reset by peer (SIGINT), and no 503 was ever seen. Cause: health_check_api has no stop-before edge, so the root cancellation stops it together with the first components. The details and caveats are in the specification's manual-verification-evidence.md.
Decision (maintainer, 2026-11-03)
Option (a): the health-check server stops last, through a stop-before edge, so it can serve 503 during the whole drain. It is reserved first, bound and spawned last, and every other supervised component stops before it. A hung component keeps it serving 503 until P, and the exit stays bounded by P with exit code 1 for any failed, panicked or aborted component. The health server's own near-instant idle drain is not budgeted inside P. The shape of the application-owned, one-way readiness state is fixed at a design review before it is wired through main.
Acceptance criteria
- Application readiness defaults to ready only after successful startup.
- Normal shutdown sets readiness to not ready before
jobs.cancel(), and a new connection to the health-check API during the drain receives HTTP 503. -
/health_checkreturns HTTP 503 while not ready and runs no downstream service probe. - The healthy
/health_checkbehaviour and body are unchanged before shutdown. - The readiness transition is one-way and safe under concurrent health requests.
- Deterministic tests cover ready, not ready, no probe fan-out, and ordering before cancellation, without OS signals.
- The health-check component stops after every other supervised component, and a failed, panicked or aborted component still gives exit code 1 within
P. - Real-binary evidence for SIGTERM and SIGINT shows timestamped 503 probes on new connections before the drain-complete and exit logs.
-
linter allpasses, and the readiness contract is documented.
The full specification is in the repository under docs/issues/open/, added by the specification-only pull request.
Not in this task, recorded as a later idea: deregister services from the Registar as they shut down, so the health list stops reporting services that are no longer available.
Activity
docs(issues): [torrust#2697] record the specification pull request in…
docs(issues): [torrust#2697] correct the stale approval statement in …
docs(pr-reviews): [torrust#2697] record the review of PR 2698
docs(issues): add issue specification for #2697
Merge #2698: docs(issues): [#2697] add specification to mark the heal…
feat(primitives): [#2697] add the one-way Readiness state
feat(health-check-api): [#2697] answer 503 without probing while the …
feat(app): [#2697] stop the health check API after every other component
feat(app): [#2697] mark the tracker not ready before cancelling on sh…
docs(shutdown): [#2697] document the readiness contract and the stop-…
docs(issues): [#2697] record the design decisions and the real-binary…
docs(issues): [torrust#2724] correct the recorded health check test b…
Merge torrust#2720: feat(app): [torrust#2697] mark the tracker not re…
chore(issues): archive closed issue #2697 spec to docs/issues/closed
Merge #2737: chore(issues): archive closed issue #2697 spec to docs/i…