fix(sports): retry syncEventSquads when Postgres closes the pooled client (BIT-32460) #271

Merged
spark merged 1 commits from fix/BIT-32460-sports-p1017-connection-closed into main 2026-11-18 20:17:38 +00:00
1 Commits
Author SHA1 Message Date
paula-alves d21612f7c4 fix(sports): retry syncEventSquads when Postgres closes the pooled client (BIT-32460)
ci / rust (pull_request) Successful in 4m7s
ci / typescript (pull_request) Successful in 10m11s
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
2026-11-18 20:06:50 +00:00