Commit 592fdc8
committed
fix(selfhost): attach a pg.Pool error listener to prevent uncaught-exception crashes
GITTENSORY-1R/1S ("uncaughtException: terminating connection due to
administrator command") and GITTENSORY-1T ("boot: Postgres not ready after
30000ms") are one incident, traced on the same container within a 29-minute
window: Postgres itself was restarted while the app held live pooled
connections. node-postgres crashes the WHOLE process with an uncaught
exception if a Pool has no "error" listener and an idle client's connection
drops -- Node's EventEmitter throws on an unhandled "error" event. The crash
then triggered a boot-retry crash loop (waitForPostgres's 30s wait, repeatedly
failing since Postgres was mid-restart) until Postgres was fully back up.
Attach pool.on("error", ...) right after the pool is constructed. The pool
already removes a broken client and opens a fresh one on the next checkout on
its own -- the only thing missing was a listener so Node stops treating an
idle client's connection-level error as unhandled. Logs via the same
console.error JSON convention used throughout this codebase so the failure
still reaches Sentry/Loki, just without taking the process down.1 parent 46581d7 commit 592fdc8
1 file changed
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
221 | 237 | | |
222 | 238 | | |
223 | 239 | | |
| |||
0 commit comments