fix: hijack the multiplexed listener's LISTEN connection out of the pool - #4486
Merged
Conversation
The multiplexed listener acquired a pool connection for LISTEN and handed pgxlisten the raw *pgx.Conn without releasing or hijacking the pgxpool.Conn. pgxlisten closes the raw connection when its listen loop exits (error, reconnect, or shutdown), but the pool still tracked the resource as acquired: every listener (re)connect permanently leaked a pool slot, and pool.Close() would block forever waiting for it. Hijack() removes the connection from the pool's accounting so pgxlisten owns its lifecycle.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a pgxpool slot leak in the Postgres multiplexed LISTEN implementation by ensuring the listener connection is removed from pool accounting, preventing gradual exhaustion of available pool connections across pgxlisten reconnects.
Changes:
- Switch the pgxlisten
Connectcallback from returningpoolConn.Conn()topoolConn.Hijack()to avoid orphaning*pgxpool.Connwrappers. - Add an explanatory comment describing why hijacking is required for pgxlisten’s ownership model and reconnect behavior.
Comment on lines
+65
to
+68
| // Hijack removes the connection from the pool's accounting: pgxlisten | ||
| // owns it and closes it when the listener exits, so the pool can be | ||
| // closed cleanly and slots aren't leaked across listener reconnects. | ||
| return poolConn.Hijack(), nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This is required for #4480
Fixes #3694
Related: #4214
Type of change
What's Changed
Hijacks a connection on the connection pool for usage with
pg_listen.Checklist
Changes have been:
🤖 AI Disclosure