fix(api): ignore realtime publish after pg pool end (BIT-31177) #1

Merged
spark merged 1 commits from fix/BIT-31177-pg-pool-after-end into main 2026-10-14 23:30:14 +01:00
Owner

Summary

  • Guard realtime NOTIFY publishers so library() is a no-op after close(), and drain in-flight queries before pool.end().
  • Suppress the known Cannot use a pool after calling end on the pool race (ERRSIG 5282eca99746 / ERRCLUSTER a49a664d04ee) instead of reporting it.
  • Regression test covers publish-after-close on createRemoteBroadcaster.

Root cause

apps/api/src/realtime.ts fire-and-forget pool.query(pg_notify…) can still run while the worker/API calls broadcaster.close() → pool.end() during SIGTERM/restart.

Test plan

  • Minimal pg repro: unguarded query-after-end reproduces the exact message; guarded publisher reports 0 errors
  • CI: pnpm --filter @photoreport/api test realtime (needs DATABASE_URL_TEST)
  • After merge + deploy to /srv/photoreport, confirm ERRCLUSTER quiet

Paperclip-Issue: BIT-31177

## Summary - Guard realtime NOTIFY publishers so `library()` is a no-op after `close()`, and drain in-flight queries before `pool.end()`. - Suppress the known `Cannot use a pool after calling end on the pool` race (ERRSIG `5282eca99746` / ERRCLUSTER `a49a664d04ee`) instead of reporting it. - Regression test covers publish-after-close on `createRemoteBroadcaster`. ## Root cause `apps/api/src/realtime.ts` fire-and-forget `pool.query(pg_notify…)` can still run while the worker/API calls `broadcaster.close()` → `pool.end()` during SIGTERM/restart. ## Test plan - [x] Minimal pg repro: unguarded query-after-end reproduces the exact message; guarded publisher reports 0 errors - [ ] CI: `pnpm --filter @photoreport/api test realtime` (needs `DATABASE_URL_TEST`) - [ ] After merge + deploy to `/srv/photoreport`, confirm ERRCLUSTER quiet Paperclip-Issue: BIT-31177
spark added 1 commit 2026-10-14 23:30:07 +01:00
fix(api): ignore realtime publish after pg pool end
ci / typescript (pull_request) Failing after 7s
ci / rust (pull_request) Successful in 7m7s
1c2f813533
Worker/API shutdown raced fire-and-forget NOTIFY queries, surfacing
"Cannot use a pool after calling end on the pool" (ERRSIG 5282eca99746).

Paperclip-Agent: Bug Squasher (urlKey bug-squasher; id 4669adc7-6368-43ef-bf27-5a601a6b7b83)
Paperclip-Issue: BIT-31177
Paperclip-Run: a5628443-aab8-4d4b-b0c5-089598292667
spark merged commit 6bd78762dc into main 2026-10-14 23:30:14 +01:00
Sign in to join this conversation.