PrismaClientKnownRequestError code P1017 ("Server has closed the connection.") was raised from personForIdentity (apps/api/src/sports/service.ts:1767) → linkSquadPerson → syncEventSquadsNow → syncEventSquads, and rejected up to the archive caller, whose .catch() logs archive: squads not synced at warn and pages the error loop (errors.bitreport.pt, ERRSIG 42f1a9a09199, ERRCLUSTER 21cd13c42286).
P1017 is transient: the server closed an idle pooled client before the next query (idle timeout, restart, pg_terminate_backend, network blip) and the @prisma/adapter-pg pool hands out a fresh client on the following attempt.
Fix
Adds isPrismaConnectionClosed() and retryOnConnectionClosed() to apps/api/src/lib/pg.ts (matching the existing isPostgresAdminShutdown() family for 57P01), and wraps the syncEventSquadsNow call in syncEventSquads with a single retry on a fresh connection.
The operation is idempotent under a re-run (upserts, findUnique lookups, unique-constraint creates whose P2002 is already caught), so replaying it on a fresh connection is safe.
Distinct from 57P01, which is handled in the worker poll loops (BIT-32448/32449/32450) and the pg.Pool error listener (BIT-32447).
Tests
New apps/api/src/lib/pg.test.ts covers isPrismaConnectionClosed (P1017 code, message-only, distinct from 57P01, non-matches) and retryOnConnectionClosed (retry once on P1017, no retry on P2002, one retry only, success path). Verified via tsx (13/13) since the API test global-setup requires a _test database unavailable in this workspace; CI runs the full suite against a photoreport_test Postgres service.
pnpm -r build and pnpm --filter @photoreport/api typecheck green.
## Problem
`PrismaClientKnownRequestError` code `P1017` ("Server has closed the connection.") was raised from `personForIdentity` (`apps/api/src/sports/service.ts:1767`) → `linkSquadPerson` → `syncEventSquadsNow` → `syncEventSquads`, and rejected up to the archive caller, whose `.catch()` logs `archive: squads not synced` at `warn` and pages the error loop (errors.bitreport.pt, ERRSIG `42f1a9a09199`, ERRCLUSTER `21cd13c42286`).
P1017 is transient: the server closed an idle pooled client before the next query (idle timeout, restart, `pg_terminate_backend`, network blip) and the `@prisma/adapter-pg` pool hands out a fresh client on the following attempt.
## Fix
Adds `isPrismaConnectionClosed()` and `retryOnConnectionClosed()` to `apps/api/src/lib/pg.ts` (matching the existing `isPostgresAdminShutdown()` family for `57P01`), and wraps the `syncEventSquadsNow` call in `syncEventSquads` with a single retry on a fresh connection.
The operation is idempotent under a re-run (upserts, `findUnique` lookups, unique-constraint creates whose `P2002` is already caught), so replaying it on a fresh connection is safe.
Distinct from `57P01`, which is handled in the worker poll loops (BIT-32448/32449/32450) and the `pg.Pool` error listener (BIT-32447).
## Tests
New `apps/api/src/lib/pg.test.ts` covers `isPrismaConnectionClosed` (P1017 code, message-only, distinct from 57P01, non-matches) and `retryOnConnectionClosed` (retry once on P1017, no retry on P2002, one retry only, success path). Verified via `tsx` (13/13) since the API test global-setup requires a `_test` database unavailable in this workspace; CI runs the full suite against a `photoreport_test` Postgres service.
`pnpm -r build` and `pnpm --filter @photoreport/api typecheck` green.
Paperclip-Issue: BIT-32460
Paperclip-Cluster: 21cd13c42286
PrismaClientKnownRequestError code P1017 ("Server has closed the
connection.") is raised when the server closes an idle pooled client
before the next query runs (idle timeout, restart, pg_terminate_backend,
network blip). The @prisma/adapter-pg pool hands out a fresh client on
the following attempt, so the failure is transient — but it surfaced
from personForIdentity -> linkSquadPerson -> syncEventSquadsNow and
rejected up to the archive caller, whose .catch() logged it at warn and
paged the error loop (errors.bitreport.pt, ERRSIG 42f1a9a09199).
Add isPrismaConnectionClosed() and retryOnConnectionClosed() to lib/pg
(matching the existing isPostgresAdminShutdown() family for 57P01), and
wrap the syncEventSquadsNow call in syncEventSquads with a single retry.
The operation is idempotent under a re-run (upserts, findUnique lookups,
unique-constraint creates whose P2002 is already caught), so replaying
it on a fresh connection is safe. Distinct from 57P01, which is handled
in the worker poll loops (BIT-32448/32449/32450) and the pg.Pool error
listener (BIT-32447).
Paperclip-Issue: BIT-32460
Paperclip-Cluster: 21cd13c42286
spark
merged commit 0c20b6ba4a into main2026-11-18 20:17:38 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Problem
PrismaClientKnownRequestErrorcodeP1017("Server has closed the connection.") was raised frompersonForIdentity(apps/api/src/sports/service.ts:1767) →linkSquadPerson→syncEventSquadsNow→syncEventSquads, and rejected up to the archive caller, whose.catch()logsarchive: squads not syncedatwarnand pages the error loop (errors.bitreport.pt, ERRSIG42f1a9a09199, ERRCLUSTER21cd13c42286).P1017 is transient: the server closed an idle pooled client before the next query (idle timeout, restart,
pg_terminate_backend, network blip) and the@prisma/adapter-pgpool hands out a fresh client on the following attempt.Fix
Adds
isPrismaConnectionClosed()andretryOnConnectionClosed()toapps/api/src/lib/pg.ts(matching the existingisPostgresAdminShutdown()family for57P01), and wraps thesyncEventSquadsNowcall insyncEventSquadswith a single retry on a fresh connection.The operation is idempotent under a re-run (upserts,
findUniquelookups, unique-constraint creates whoseP2002is already caught), so replaying it on a fresh connection is safe.Distinct from
57P01, which is handled in the worker poll loops (BIT-32448/32449/32450) and thepg.Poolerror listener (BIT-32447).Tests
New
apps/api/src/lib/pg.test.tscoversisPrismaConnectionClosed(P1017 code, message-only, distinct from 57P01, non-matches) andretryOnConnectionClosed(retry once on P1017, no retry on P2002, one retry only, success path). Verified viatsx(13/13) since the API test global-setup requires a_testdatabase unavailable in this workspace; CI runs the full suite against aphotoreport_testPostgres service.pnpm -r buildandpnpm --filter @photoreport/api typecheckgreen.Paperclip-Issue: BIT-32460
Paperclip-Cluster: 21cd13c42286
PrismaClientKnownRequestError code P1017 ("Server has closed the connection.") is raised when the server closes an idle pooled client before the next query runs (idle timeout, restart, pg_terminate_backend, network blip). The @prisma/adapter-pg pool hands out a fresh client on the following attempt, so the failure is transient — but it surfaced from personForIdentity -> linkSquadPerson -> syncEventSquadsNow and rejected up to the archive caller, whose .catch() logged it at warn and paged the error loop (errors.bitreport.pt, ERRSIG 42f1a9a09199). Add isPrismaConnectionClosed() and retryOnConnectionClosed() to lib/pg (matching the existing isPostgresAdminShutdown() family for 57P01), and wrap the syncEventSquadsNow call in syncEventSquads with a single retry. The operation is idempotent under a re-run (upserts, findUnique lookups, unique-constraint creates whose P2002 is already caught), so replaying it on a fresh connection is safe. Distinct from 57P01, which is handled in the worker poll loops (BIT-32448/32449/32450) and the pg.Pool error listener (BIT-32447). Paperclip-Issue: BIT-32460 Paperclip-Cluster: 21cd13c42286