You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: close database pools and notification listener on shutdown
Pool closing was commented out ("@@ to be fixed, now blocks"), so the
process exited with every pgx pool open and the listener's dedicated
connection up: Postgres saw abrupt connection resets on each stop, and
connection slots lingered until TCP teardown.
Two things made Close() block:
- pgxpool.Pool.Close() waits for acquired connections, and with the old
1-second shutdown window HTTP.Shutdown regularly gave up while
handlers were still running and holding connections.
- NotificationListener.Stop() only closed a channel that the listen
loop checked between notifications, while the loop normally sits
blocked inside WaitForNotification — the goroutine (and its
connection) survived Stop.
Now the listener's Stop cancels the loop context, which interrupts
WaitForNotification, closes the connection cleanly with a bounded
fresh context (so Postgres receives a Terminate message), and waits
for the goroutine to exit — also when racing another Stop.
Server.Shutdown then closes the engine after the HTTP drain completes
— at that point no handler holds a connection — bounding the wait by
the shutdown context (plus a 5s backstop when it has no deadline) so
an expired drain window cannot hang the process past the supervisor's
grace period.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,7 @@
20
20
* Session watcher no longer deadlocks when paused.
21
21
***SIGTERM** — the server now shuts down gracefully on SIGTERM (the default stop signal of Docker, Kubernetes and systemd), not only on SIGINT/Ctrl-C. A raw SIGTERM previously terminated the process immediately, cutting in-flight requests and resetting database connections.
22
22
***Exit status** — a graceful shutdown now exits with status 0; it previously exited 1, which supervisors interpret as a crash.
23
+
***Database connections on shutdown** — connection pools and the notification listener's dedicated connection are now closed after the HTTP server drains, so Postgres sees clean disconnects instead of connection resets on every stop. `NotificationListener.Stop()` now interrupts a pending `WaitForNotification` and waits for the listener goroutine to exit before returning.
0 commit comments