Skip to content

feat(health-check-api): [#2324] migrate token lifecycle - #2336

Merged
josecelano merged 10 commits into
torrust:developfrom
josecelano:2324-1488-si-13-migrate-health-check-api-token-lifecycle
Sep 25, 2026
Merged

josecelano merged 10 commits into
torrust:developfrom
josecelano:2324-1488-si-13-migrate-health-check-api-token-lifecycle

Conversation

@josecelano

Copy link
Copy Markdown
Member

Summary

  • Add an additive token-aware health-check API start path (server::start_with_cancellation) that binds, serves, registers the service, and drains through the token-aware Axum helper with a 5-second budget. Registration failure cancels and joins both children and releases the listener. The legacy Halted-based start path and environment start/stop are unchanged and share the same router.
  • Migrate the health_check_api bootstrap component to a JobManager child token. The component owns the server and drain-controller tasks through TokenAwareServerTask, created before the component future is returned, and joins both before reporting one named outcome on cancellation, independent completion, panic, or runtime error.
  • Record maintainer decisions, manual SIGTERM/rebind evidence, verification, the independent task review, and a retrospective. Update the health-check rows of the shutdown task inventory.

Readiness and response behavior are unchanged; SI-21 owns unhealthy-during-shutdown.

Files/packages touched

  • packages/axum-health-check-api-server (src/server.rs, Cargo.toml: adds thiserror, tokio-util)
  • src/bootstrap/jobs/health_check_api.rs, src/app.rs
  • docs/features/shutdown-process/task-inventory.md
  • docs/issues/open/2324-1488-si-13-migrate-health-check-api-token-lifecycle/

Validation

  • cargo test -p torrust-tracker-axum-health-check-api-server (3 unit tests, 8 legacy contract tests)
  • cargo test -p torrust-tracker --lib -- health_check_api (component supervision, drop-before-run listener release, bootstrap propagation)
  • The drop-before-run regression test was proved by mutation: creating the owner inside the returned future makes it fail.
  • linter all, pre-commit and pre-push hooks (nightly format/check/docs and full test suite), nightly Rust 1.100.0-nightly
  • Direct tracker-binary SIGTERM twice on the same health-check binding: exit 0, token-aware drain logged, health_check_api reported cooperative cancellation, immediate listener rebind

Follow-ups (not in this PR)

Part of EPIC #1488.

Closes #2324

Copilot AI lite review requested due to automatic review settings September 24, 2026 17:15
@josecelano josecelano self-assigned this Sep 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

This PR migrates the health-check API lifecycle to a token-aware shutdown model while keeping the legacy Halted-based path intact.

Changes:

  • Add a token-aware server startup path (server::start_with_cancellation) that binds, serves, registers, and drains via an injected CancellationToken.
  • Update the health-check bootstrap job to supervise a token-owned server + drain controller (TokenAwareServerTask) and join both before reporting outcomes.
  • Add focused tests and documentation evidence for cancellation/drain behavior, listener release, and bootstrap propagation.
File Description
src/​bootstrap/​jobs/​health_check_api.rs Switches health check job to token-aware startup and supervision; adds component-level tests.
src/​app.rs Passes a JobManager child cancellation token into the health-check job; adds bootstrap test coverage.
packages/​axum-health-check-api-server/​src/​server.rs Introduces start_with_cancellation, shared router extraction, and unit tests for registration/drain/rollback.
packages/​axum-health-check-api-server/​Cargo.toml Adds dependencies needed for token-aware lifecycle and error typing (tokio-util, thiserror).
docs/​issues/​open/​2324-1488-si-13-migrate-health-check-api-token-lifecycle/​verification.md Records deterministic test evidence and manual verification links for the migration.
docs/​issues/​open/​2324-1488-si-13-migrate-health-check-api-token-lifecycle/​manual-verification-evidence.md Adds direct SIGTERM/rebind manual evidence for token-driven drain and clean exit.
docs/​issues/​open/​2324-1488-si-13-migrate-health-check-api-token-lifecycle/​implementation-retrospective.md Captures key lifecycle/ownership lessons learned and follow-ups.
docs/​issues/​open/​2324-1488-si-13-migrate-health-check-api-token-lifecycle/​agent-review-reports.md Adds an independent review report entry for the work.
docs/​issues/​open/​2324-1488-si-13-migrate-health-check-api-token-lifecycle/​ISSUE.md Updates spec status, decisions, verification, and completion review notes.
docs/​features/​shutdown-process/​task-inventory.md Updates shutdown inventory rows to reflect token-aware health-check ownership and drain joining.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/bootstrap/jobs/health_check_api.rs Resolved
Comment thread src/bootstrap/jobs/health_check_api.rs Resolved
…art path

Add start_with_cancellation, which binds, serves, registers the service, and drains through graceful_shutdown_on_cancellation with a 5-second budget. Registration failure cancels and joins both children and releases the listener. The legacy Halted-based start path is unchanged and shares the router.
…ecycle

The health_check_api component now receives a JobManager child token, starts the token-aware server, and joins its server and drain-controller children before reporting one named outcome. Independent completion, panic, and runtime error paths cancel and join the drain controller first.
…ning the component

Create the TokenAwareServerTask owner before returning the component future, so dropping an unpolled component aborts the server and drain controller and releases the listener. On the cancellation path, join the drain controller before mapping a server join error. Found by the independent completion review; the new regression test fails when the owner is created inside the future.
… review

Add manual SIGTERM and listener-rebind evidence, fill in the verification record, save the independent task review, and record the retrospective for the ownership fix.
…stop

Use the listener's actual local address instead of the configured bind address, which differs for ephemeral ports.
…e retry

Sleep briefly between bind attempts instead of spinning with yield_now while waiting for the listener to be released.
@josecelano
josecelano force-pushed the 2324-1488-si-13-migrate-health-check-api-token-lifecycle branch from ca67acf to 50be849 Compare September 24, 2026 20:03
@josecelano

Copy link
Copy Markdown
Member Author

ACK 50be849

@josecelano
josecelano merged commit b0f5658 into torrust:develop Sep 25, 2026
21 checks passed
josecelano added a commit that referenced this pull request Sep 26, 2026
2e36b46 docs(pr-reviews): point PR #2336 audit to the archived #2324 spec (Jose Celano)
4f74f65 docs(issues): add issue specification for #2342 (Jose Celano)

Pull request description:

  ## Summary

  Spec-only PR for SI-14 of EPIC #1488: promote the UDP token-lifecycle draft to open issue #2342 before implementation starts.

  - Rewrite the SI-14 spec against the current code after SI-13 merged. It records three ownership gaps in the UDP path (legacy drop path panics and detaches the receive loop, launcher abort detaches it, receive errors reported as normal completion) and maintainer-approved decisions D1-D6 with pros and cons: cooperative token stop in the receive loop, a flattened token-aware path, explicit receive failures, a single-task drop-safe owner, a safe legacy launcher adapter, and a UDP throughput baseline before implementation plus a second measurement after it.
  - Link #2342 from the EPIC roadmap (step 10) and update references in the SI-9, SI-15, and SI-17 drafts.
  - Point the PR #2336 review audit's frontmatter to the archived #2324 spec.

  ## Files touched

  - `docs/issues/open/2342-1488-si-14-migrate-udp-receive-reset-token-lifecycle/` (moved from `docs/issues/drafts/`)
  - `docs/issues/open/1488-overhaul-tracker-shutdown/ISSUE.md`
  - `docs/issues/drafts/1488-si-9-improve-udp-shutdown/`, `1488-si-15-define-udp-active-request-policy/`, `1488-si-17-migrate-standalone-udp-environment/`
  - `docs/pr-reviews/pr-2336-review/PR-REVIEW.md`

  ## Validation

  - `linter all` (including local link checks) via the pre-commit hook
  - No code changes

  Related to #2342

ACKs for top commit:
  josecelano:
    ACK 2e36b46

Tree-SHA512: aa34f2c3e232d55542a5dc8729563fd43fb68264380e66e6894b46aaf94b17b7f9536169c9001389659c9a0cd3d872ab2566eb7c9295d88d3d3d4f524bad94df

This branch was previously deployed

1 inactive deployment
coverage — 50be849b Deployed Sep 24, 2026 by josecelano via Generate Coverage Report #2304
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate health-check API to token lifecycle

2 participants