Skip to content

Return 503 from an unhealthy health check - #370

Merged
lesnik512 merged 1 commit into
mainfrom
health-503
Oct 29, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
health-503

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Closes #319.

An unhealthy health check now answers 503 Service Unavailable instead of 500, on FastAPI, Litestar, FastMCP and FastStream. The route is unhealthy when a probe returns False or raises, and on FastStream also when a broker ping fails. The JSON body is unchanged.

A 500 says the handler failed. A 503 says the service can't serve right now, so alerting can tell a dependency the probe found down apart from a crashing handler. Both are 5xx, so a rule on all 5xx still fires. Kubernetes treats any status from 200 to 399 as success, so probes behave the same as before.

Changes

  • FastAPI, Litestar and FastMCP use HTTP_503_SERVICE_UNAVAILABLE from fastapi.status, litestar.status_codes and starlette.status. FastStream's literal changes from 500 to 503.
  • The "Health checks" section of configuration.md gives the new status.

Tests

Written first, as the issue lists. The two failing cases in HEALTH_PROBE_CASES and the three FastStream assertions now expect 503. On main, 11 cases failed across all four frameworks:

  • the one-returns-false and one-raises cases of each framework's test_*_health_check_runs_probes
  • test_faststream_bootstrap_health_check_wo_broker
  • test_faststream_health_check_fails_when_second_broker_is_down
  • test_faststream_health_check_fails_on_broker_ping_despite_passing_probe

The full suite passes, 557 tests at 100% coverage (just test-ci). just lint (including ty), just adr-check and just docs-build pass too. No floor changes.

Breaking changes

Monitoring or load-balancer rules that match a 500 from the health route stop matching. Match 503, or any 5xx.

@lesnik512 lesnik512 added this to the 2.0.0 milestone Oct 29, 2026
@lesnik512
lesnik512 merged commit 898e7ef into main Oct 29, 2026
37 checks passed
@lesnik512
lesnik512 deleted the health-503 branch October 29, 2026 14:19
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.

Return 503 from an unhealthy health check

1 participant