Scrum4Me/app
janpeter visser 801da46f11 fix(realtime): force-destroy pg socket on cleanup timeout (SSE leak)
Three SSE-routes (solo, backlog, notifications) each create a long-
running pg.Client that LISTENs on scrum4me_changes. On abrupt close
(Fast Refresh, browser refresh, Vercel function recycle) the
pgClient.end()-await sometimes hangs silently, leaving the underlying
socket connected to Postgres. The connection stays in 'idle' on Neon's
side and after ~10-20 reconnects the connection-pool fills up — new
SSE connects fail with ERR_INCOMPLETE_CHUNKED_ENCODING in the browser.

Fix: shared `closePgClientSafely` helper that races client.end()
against a 2 s timeout; on timeout it force-destroys the underlying
socket so the OS releases the FD and Postgres notices the disconnect.

Validated by direct DB inspection: 18 stale 'idle LISTEN'-connections
were piled up before the fix; after manual pg_terminate_backend cleanup
the SSE-stream stabilised. This change makes the pile-up impossible
going forward.

- new lib/realtime/pg-client-cleanup.ts
- 3 routes use the helper instead of bare `await pgClient.end()`
- 3 unit tests for the helper (timely-end, hang-falls-back-to-destroy,
  end-rejection-is-swallowed)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 20:03:15 +02:00
..
(app) feat(insights): port unique files from closed bundle-PRs (#41) 2026-05-01 16:44:53 +02:00
(auth) M10: Password-loze inlog via QR-pairing (ST-1001..ST-1008) (#12) 2026-04-28 00:01:04 +02:00
_components/tasks M14: TaskDialog (create/edit) + story auto-promotion (#21) 2026-04-30 16:55:20 +02:00
api fix(realtime): force-destroy pg socket on cleanup timeout (SSE leak) 2026-05-01 20:03:15 +02:00
debug-env chore(debug): add /debug-env page to verify Vercel env-var presence 2026-04-27 10:37:46 +02:00
debug-realtime chore: debug-realtime tooling for SSE pipeline diagnostics (#20) 2026-04-29 20:35:40 +02:00
styles M14: TaskDialog (create/edit) + story auto-promotion (#21) 2026-04-30 16:55:20 +02:00
apple-icon.png chore: documentatie naar docs/, iconen bijgewerkt, theme.css verplaatst 2026-04-24 22:51:42 +02:00
favicon.ico chore: documentatie naar docs/, iconen bijgewerkt, theme.css verplaatst 2026-04-24 22:51:42 +02:00
globals.css M14: TaskDialog (create/edit) + story auto-promotion (#21) 2026-04-30 16:55:20 +02:00
icon.png chore: documentatie naar docs/, iconen bijgewerkt, theme.css verplaatst 2026-04-24 22:51:42 +02:00
layout.tsx Add analytics and documentation updates 2026-04-25 15:11:51 +02:00
page.tsx feat(landing): highlight realtime updates and beta/desktop-first notice 2026-04-27 20:29:51 +02:00