Health check: treat 3xx as up (gateway :port now redirects)

The HTTP health poller marked anything >=300 as down. With subdomain routing the
gateway's :<port> health path returns 302 (redirect to the dashboard subdomain),
so castle-gateway showed "down" despite being healthy. Accept <400: a 2xx or 3xx
means the server answered; only 4xx/5xx (or a connection error) is down.
This commit is contained in:
2026-06-30 21:06:08 -07:00
parent 4ff6af8f4d
commit 478e3c57dd

View File

@@ -46,7 +46,9 @@ async def _check_http(client: httpx.AsyncClient, name: str, url: str) -> HealthS
try: try:
resp = await client.get(url) resp = await client.get(url)
latency = int((time.monotonic() - start) * 1000) latency = int((time.monotonic() - start) * 1000)
if resp.status_code < 300: # 2xx/3xx = the server answered (a 3xx redirect still means it's alive —
# e.g. the gateway's :<port> now redirects to the dashboard subdomain).
if resp.status_code < 400:
return HealthStatus(id=name, status="up", latency_ms=latency) return HealthStatus(id=name, status="up", latency_ms=latency)
return HealthStatus(id=name, status="down", latency_ms=latency) return HealthStatus(id=name, status="down", latency_ms=latency)
except httpx.HTTPError: except httpx.HTTPError: