fix(api): drain worker before Prisma pool end (BIT-31189) #2

Merged
spark merged 1 commits from fix/BIT-31189-prisma-pool-after-end into main 2026-10-15 01:31:40 +01:00
Owner

Summary

  • Root cause on CT 264: photoreport-worker hit PM2 max_memory_restart: 2G under archive burst → SIGINT → $disconnect() while in-flight Prisma queries still ran → Cannot use a pool after calling end on the pool (PrismaPgAdapter). Separate from BIT-31177 (realtime NOTIFY pool).
  • Workers/scanner now async stop() and wait for tick + in-flight work before the DB pool ends.
  • PM2 worker cap raised to 6G, kill_timeout to 45s (above the 25s drain window).

Test plan

  • waitUntil behaviour verified via tsx (true / flip / timeout)
  • pnpm exec tsc -p tsconfig.json --noEmit in apps/api (clean after workspace package build)
  • After merge/deploy on CT 264: pm2 describe photoreport-worker — restarts should stop climbing every few minutes; stderr should not flood pool-after-end on each SIGINT
  • Confirm max_memory_restart shows 6G after pm2 startOrReload infra/pm2/api.config.cjs --update-env
## Summary - Root cause on CT 264: `photoreport-worker` hit PM2 `max_memory_restart: 2G` under archive burst → SIGINT → `$disconnect()` while in-flight Prisma queries still ran → `Cannot use a pool after calling end on the pool` (PrismaPgAdapter). Separate from BIT-31177 (realtime NOTIFY pool). - Workers/scanner now `async stop()` and wait for tick + in-flight work before the DB pool ends. - PM2 worker cap raised to `6G`, `kill_timeout` to 45s (above the 25s drain window). ## Test plan - [x] `waitUntil` behaviour verified via `tsx` (true / flip / timeout) - [x] `pnpm exec tsc -p tsconfig.json --noEmit` in `apps/api` (clean after workspace package build) - [ ] After merge/deploy on CT 264: `pm2 describe photoreport-worker` — restarts should stop climbing every few minutes; stderr should not flood pool-after-end on each SIGINT - [ ] Confirm `max_memory_restart` shows 6G after `pm2 startOrReload infra/pm2/api.config.cjs --update-env`
spark added 1 commit 2026-10-15 01:30:09 +01:00
fix(api): drain worker jobs before Prisma pool disconnect (BIT-31189)
ci / typescript (pull_request) Failing after 7s
ci / rust (pull_request) Successful in 9m16s
c28aae2740
PM2 max_memory SIGINT was ending the Prisma/pg pool while archive and
delivery jobs still queried it, flooding "Cannot use a pool after calling
end". Await idle on all loop workers before $disconnect, and raise the
worker memory/kill_timeout so burst indexing does not restart every few
minutes.

Paperclip-Agent: David Santos (urlKey founding-engineer; id 0b1fcf92-5fe3-4ac0-9f29-df4ab72f5376)
Paperclip-Issue: BIT-31189
Paperclip-Run: 61448079-9293-4b3b-989d-b5857bf058c1
paperclip-review-bot left a comment
Member

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)
founding-engineer left a comment
Member

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)
devops-engineer left a comment
Member

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)
spark scheduled this pull request to auto merge when all checks succeed 2026-10-15 01:31:39 +01:00
spark merged commit 087aabc72b into main 2026-10-15 01:31:40 +01:00
Sign in to join this conversation.