fix(sports): downgrade P1001 unreachable-database errors in syncEventSquads to info (BIT-32463) #273

Merged
spark merged 1 commits from fix/BIT-32463-sports-p1001-unreachable into main 2026-11-18 20:47:52 +00:00
Owner

What

A Postgres restart or a downed route makes the database unreachable (Prisma P1001: "Can't reach database server at 127.0.0.1:5432") mid-syncEventSquads. The liga squad re-read catch logged it at warn ("liga squad re-read failed"), paging the error loop for a transient blip — and uncaught P1001 from the initial findUnique or the second squad loop propagated to the caller's warn too.

Fix

Detect P1001 with the shared isPrismaServerUnreachable helper (lib/pg.ts, added in BIT-32462 for the archive worker) and log at info instead:

  • Liga re-read catch (syncEventSquadsNow): on P1001, log info and return result early — every remaining query would fail the same way.
  • syncEventSquads wrapper: catch P1001 from retryOnConnectionClosed and return zeros with an info log.

The next scheduled sync retries once the server is back. Same pattern as archive/faces/develop/autopilot (BIT-32448/32449/32450/32462).

Tests

3 new tests in apps/api/src/sports/service.test.ts:

  • P1001 in the initial event.findUnique → info log, zeros returned, no warn.
  • P1001 in savePlayers during the liga re-read → info log, zeros returned, no warn, second loop's findMany not called.
  • Non-P1001 error in the liga re-read → still warns.

Paperclip-Issue: BIT-32463

## What A Postgres restart or a downed route makes the database unreachable (Prisma **P1001**: "Can't reach database server at 127.0.0.1:5432") mid-`syncEventSquads`. The liga squad re-read catch logged it at `warn` ("liga squad re-read failed"), paging the error loop for a transient blip — and uncaught P1001 from the initial `findUnique` or the second squad loop propagated to the caller's `warn` too. ## Fix Detect P1001 with the shared `isPrismaServerUnreachable` helper (lib/pg.ts, added in BIT-32462 for the archive worker) and log at `info` instead: - **Liga re-read catch** (`syncEventSquadsNow`): on P1001, log info and `return result` early — every remaining query would fail the same way. - **`syncEventSquads` wrapper**: catch P1001 from `retryOnConnectionClosed` and return zeros with an info log. The next scheduled sync retries once the server is back. Same pattern as archive/faces/develop/autopilot (BIT-32448/32449/32450/32462). ## Tests 3 new tests in `apps/api/src/sports/service.test.ts`: - P1001 in the initial `event.findUnique` → info log, zeros returned, no warn. - P1001 in `savePlayers` during the liga re-read → info log, zeros returned, no warn, second loop's `findMany` not called. - Non-P1001 error in the liga re-read → still warns. Paperclip-Issue: BIT-32463
spark added 1 commit 2026-11-18 20:35:57 +00:00
fix(sports): downgrade P1001 unreachable-database errors in syncEventSquads to info (BIT-32463)
ci / rust (pull_request) Successful in 4m56s
ci / typescript (pull_request) Successful in 10m37s
6232b41e5c
A Postgres restart or a downed route makes the database unreachable
(Prisma P1001: "Can't reach database server at <host>:<port>") mid
syncEventSquads — inside savePlayers' findMany during the liga squad
re-read, or at the initial event findUnique, or in the second squad
loop. The liga re-read catch logged it at warn ("liga squad re-read
failed"), paging the error loop for a transient blip, and the outer
syncEventSquads let uncaught P1001 propagate to the caller's warn.

Detect P1001 with the shared isPrismaServerUnreachable helper
(lib/pg.ts, added in BIT-32462 for the archive worker) and log at
info instead: in the liga re-read catch, return the partial result
early; in the syncEventSquads wrapper, catch P1001 from
retryOnConnectionClosed and return zeros. The next scheduled sync
retries once the server is back. Same pattern as archive/faces/
develop/autopilot (BIT-32448/32449/32450/32462).

Paperclip-Issue: BIT-32463
spark merged commit 16030b9249 into main 2026-11-18 20:47:52 +00:00
Sign in to join this conversation.