fix(sports): stop syncEventSquads when P1017 exhausts the retry (BIT-32475) #279

Merged
spark merged 1 commits from fix/BIT-32475-sports-p1017-connection-closed-retry-exhausted into main 2026-11-18 22:35:46 +00:00
Owner

Summary

The error loop reported PrismaClientKnownRequestError P1017 ("Server has closed the connection.") from linkSquadPerson → person.findFirst (apps/api/src/sports/service.ts).

retryOnConnectionClosed (BIT-32460) already retries syncEventSquadsNow once on a fresh client. When the server keeps closing the pool (a restart or pg_terminate_backend tearing through clients), the second attempt fails the same way and the rejection escaped the syncEventSquads catch — which only matched isPrismaServerUnreachable (P1001/57P03). The resulting warn paged the error loop for a transient blip.

Fix

Treat a P1017 that survives the retry like the existing unreachable handling (BIT-32463/BIT-32470/BIT-32471): log at info and stop the sync, letting the next scheduled call retry once the pool is stable.

Tests

  • New p1017 helper + syncEventSquads downgrades a P1017 server-closed connection that exhausts the retry (BIT-32475) test (asserts info log database connection closed, no warn, zero result).
  • pnpm --filter @photoreport/api typecheck green.
  • Unit tests (src/lib/pg.test.ts, src/sports/service.test.ts) green: 26 passed.

Paperclip-Issue: BIT-32475
Paperclip-Cluster: 792bb5de9fcb

## Summary The error loop reported `PrismaClientKnownRequestError` **P1017** ("Server has closed the connection.") from `linkSquadPerson` → `person.findFirst` (`apps/api/src/sports/service.ts`). `retryOnConnectionClosed` (BIT-32460) already retries `syncEventSquadsNow` once on a fresh client. When the server keeps closing the pool (a restart or `pg_terminate_backend` tearing through clients), the second attempt fails the same way and the rejection escaped the `syncEventSquads` catch — which only matched `isPrismaServerUnreachable` (P1001/57P03). The resulting `warn` paged the error loop for a transient blip. ## Fix Treat a P1017 that survives the retry like the existing unreachable handling (BIT-32463/BIT-32470/BIT-32471): log at `info` and stop the sync, letting the next scheduled call retry once the pool is stable. ## Tests - New `p1017` helper + `syncEventSquads downgrades a P1017 server-closed connection that exhausts the retry (BIT-32475)` test (asserts info log `database connection closed`, no warn, zero result). - `pnpm --filter @photoreport/api typecheck` green. - Unit tests (`src/lib/pg.test.ts`, `src/sports/service.test.ts`) green: 26 passed. Paperclip-Issue: BIT-32475 Paperclip-Cluster: 792bb5de9fcb
spark added 1 commit 2026-11-18 22:22:54 +00:00
fix(sports): stop syncEventSquads when P1017 exhausts the retry (BIT-32475)
ci / rust (pull_request) Successful in 5m54s
ci / typescript (pull_request) Successful in 11m6s
67adf1ce70
The error loop reported PrismaClientKnownRequestError P1017 ("Server has
closed the connection.") from linkSquadPerson -> person.findFirst.
retryOnConnectionClosed (BIT-32460) already retries syncEventSquadsNow once
on a fresh client; when the server keeps closing the pool (a restart or
pg_terminate_backend tearing through clients), the second attempt fails the
same way and the rejection escaped the syncEventSquads catch, which only
matched isPrismaServerUnreachable (P1001/57P03). The warn paged the error
loop for a transient blip.

Treat a P1017 that survives the retry like the existing unreachable
handling: log at info and stop the sync, letting the next scheduled call
retry once the pool is stable. Mirrors BIT-32463/BIT-32470/BIT-32471.

Paperclip-Issue: BIT-32475
Paperclip-Cluster: 792bb5de9fcb
spark merged commit 5b80e614f6 into main 2026-11-18 22:35:46 +00:00
Sign in to join this conversation.