Skip to content

feat(health): bounded DB connectivity check on /health#126

Merged
AquiGorka merged 1 commit into
mainfrom
feat/health-db-check
Jun 22, 2026
Merged

feat(health): bounded DB connectivity check on /health#126
AquiGorka merged 1 commit into
mainfrom
feat/health-db-check

Conversation

@AquiGorka

Copy link
Copy Markdown
Contributor

What

/api/v1/health returned a static {status:"ok"} and never touched the database, so it reported healthy even when the DB was unreachable (the trigger for this work: council looked healthy while its DB cluster was in error).

This adds a bounded SELECT 1 connectivity probe to /health:

  • deps.db: "ok" | "error" added to the response body.
  • HTTP 503 when the DB probe fails; 200 when it passes.
  • Probe is bounded by a 2s timeout (DB_HEALTH_TIMEOUT_MS), well under the Fly http_service check timeout = 3s, so a slow/unreachable DB resolves to a fast 503 instead of hanging the endpoint.

Why it does not re-break deploys

SELECT 1 tests connectivity only, not schema. Migrations run as the Fly release_command (bluegreen) before new machines serve traffic, and even on a still-migrating boot a reachable Postgres returns db:ok. Only a genuine unreachable/unresponsive DB reports error. Combined with the existing grace_period = 60s, this will not flap the deploy health-gate.

Tests

New db-check_test.ts covers all three paths: ok (probe resolves), error (probe rejects = connection failure), and error (probe exceeds timeout). Full unit suite green (128 passed).

Version

0.9.2 → 0.9.3

The /health endpoint returned a static {status:"ok"} and never touched the
database, so it reported healthy even when the DB was unreachable. Run a
bounded SELECT 1 (2s timeout) on each request, surface the result as deps.db,
and return 503 when the probe fails.

SELECT 1 tests connectivity only (not schema), so a still-migrating fresh boot
reports db:ok as long as Postgres is reachable — this does not flap the Fly
deploy health-gate. Bump 0.9.2 -> 0.9.3.
@AquiGorka
AquiGorka merged commit 30db7b9 into main Jun 22, 2026
7 checks passed
@AquiGorka
AquiGorka deleted the feat/health-db-check branch June 22, 2026 15:40
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.

1 participant