Skip to content

CE: Return 503 health when DB down + graceful session errors#299

Merged
ericflo merged 2 commits intomainfrom
ce/health-503-and-graceful-sessions
Apr 15, 2026
Merged

CE: Return 503 health when DB down + graceful session errors#299
ericflo merged 2 commits intomainfrom
ce/health-503-and-graceful-sessions

Conversation

@ericflo
Copy link
Copy Markdown
Owner

@ericflo ericflo commented Apr 15, 2026

What

Two fixes for DB-unavailable scenarios:

  1. /health returns 503 (not 200) when db_connected is false, so k8s readiness probe fails correctly
  2. Session-dependent routes show a styled 503 error page instead of raw tower-sessions error text ("Can't extract session. Is SessionManagerLayer enabled?")

How

  • Health endpoint now returns StatusCode::SERVICE_UNAVAILABLE with {"status":"degraded",...} when DB ping fails
  • New session_guard middleware checks for Session in request extensions before session-dependent routes; returns a styled HTML 503 page when missing
  • Session-exempt routes (/, /health, /robots.txt, /sitemap.xml, /favicon.ico, /checkout/cancel, /webhook/*) pass through unaffected

Why

When the cloud Postgres is unreachable, the pod still passes k8s readiness checks and routes traffic. Users see raw error strings on pricing/signup/login/dashboard pages.

Test plan

  • All 54 existing tests pass (36 unit + 18 integration)
  • Health test updated: expects 503 + "degraded" when db is None
  • Session-dependent route tests updated: expect styled 503 instead of raw 500
  • Non-session routes (landing, robots, sitemap, favicon, webhook, checkout/cancel) still return their normal responses

Cloud Eric added 2 commits April 15, 2026 21:22
- Health endpoint returns HTTP 503 with status 'degraded' when database
  is unreachable, so k8s readiness probe correctly fails
- Session guard middleware returns styled 503 page for session-dependent
  routes when SessionManagerLayer is not available, replacing raw
  tower-sessions error text
- Updated integration tests to match new behavior
@ericflo ericflo merged commit 9335462 into main Apr 15, 2026
12 checks passed
@ericflo ericflo deleted the ce/health-503-and-graceful-sessions branch April 15, 2026 21:28
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