Stop the health-check error loop on Postgres connection exhaustion (BIT-33548) #321

Closed
jos-alves wants to merge 1 commits from task/BIT-33548-health-connection-exhaustion into main
pull from: task/BIT-33548-health-connection-exhaustion
Member

Problem

The /health endpoint ran db.$queryRaw\SELECT 1`with no error handling. When PostgreSQL hitsmax_connections(error 53300 — "remaining connection slots are reserved for roles with the SUPERUSER attribute"), the query threwPrismaClientKnownRequestError`, the error handler logged it as "unhandled error", and the reporter sent it to errors.bitreport.pt — creating an error loop of one-off incidents from every health check.

Fix

Two changes:

  1. app.ts — health check degrades gracefully. The /health endpoint now catches DB failures and returns 503 { status: "degraded" } instead of throwing. A connection-starved health check reports degraded health rather than generating an error report.

  2. reporter.ts — 53300 added to transient filter. isTransientDatabaseError now filters 53300 (pool exhaustion) alongside the existing 57P01/57P03/P1001/P1017 filters, so even if a 53300 surfaces through another code path it does not trip the error loop.

Tests

  • reporter.test.ts: added 53300 to the existing transient DB error suppression test.
  • auth.test.ts: added a test that verifies /health returns 503 { status: "degraded" } when the database is unreachable.

Build and typecheck pass. The reporter filter and health-check degradation were both verified against the compiled output.

Paperclip-Issue: BIT-33548

## Problem The `/health` endpoint ran `db.$queryRaw\`SELECT 1\`` with no error handling. When PostgreSQL hits `max_connections` (error 53300 — "remaining connection slots are reserved for roles with the SUPERUSER attribute"), the query threw `PrismaClientKnownRequestError`, the error handler logged it as "unhandled error", and the reporter sent it to errors.bitreport.pt — creating an error loop of one-off incidents from every health check. ## Fix Two changes: 1. **`app.ts` — health check degrades gracefully.** The `/health` endpoint now catches DB failures and returns `503 { status: "degraded" }` instead of throwing. A connection-starved health check reports degraded health rather than generating an error report. 2. **`reporter.ts` — 53300 added to transient filter.** `isTransientDatabaseError` now filters 53300 (pool exhaustion) alongside the existing 57P01/57P03/P1001/P1017 filters, so even if a 53300 surfaces through another code path it does not trip the error loop. ## Tests - `reporter.test.ts`: added 53300 to the existing transient DB error suppression test. - `auth.test.ts`: added a test that verifies `/health` returns 503 `{ status: "degraded" }` when the database is unreachable. Build and typecheck pass. The reporter filter and health-check degradation were both verified against the compiled output. Paperclip-Issue: BIT-33548
tiago-neves added 1 commit 2026-12-04 07:43:33 +00:00
Stop the health-check error loop on Postgres connection exhaustion (BIT-33548)
ci / typescript (push) Skipped
ci / rust (push) Skipped
ci / rust (pull_request) Successful in 4m33s
ci / typescript (pull_request) Successful in 11m56s
2ec4f263b6
The /health endpoint ran db.$queryRaw`SELECT 1` with no error handling.
When PostgreSQL hits max_connections (error 53300), the query threw
PrismaClientKnownRequestError, the error handler logged it as 'unhandled
error', and the reporter sent it to errors.bitreport.pt — creating an
error loop of one-off incidents from every health check.

Two fixes:
- /health now catches DB failures and returns 503 { status: 'degraded' }
  instead of throwing, so a connection-starved health check degrades
  gracefully rather than generating an error report.
- isTransientDatabaseError now filters 53300 (pool exhaustion) alongside
  the existing 57P01/57P03/P1001/P1017 filters, so even if a 53300 surfaces
  through another code path it does not trip the error loop.

Paperclip-Issue: BIT-33548
spark added 1 commit 2026-12-04 08:00:23 +00:00
Merge branch 'main' into task/BIT-33548-health-connection-exhaustion
ci / typescript (push) Skipped
ci / rust (push) Skipped
ci / rust (pull_request) Successful in 5m45s
ci / typescript (pull_request) Successful in 11m4s
86f37433a8
jos-alves closed this pull request 2026-12-04 08:03:10 +00:00

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.