Skip to content

fix: hijack the multiplexed listener's LISTEN connection out of the pool - #4486

Merged
abelanger5 merged 1 commit into
mainfrom
belanger/fix-listener-pool-leak
Jul 22, 2026
Merged

fix: hijack the multiplexed listener's LISTEN connection out of the pool#4486
abelanger5 merged 1 commit into
mainfrom
belanger/fix-listener-pool-leak

Conversation

@abelanger5

Copy link
Copy Markdown
Contributor

Description

This is required for #4480

Fixes #3694

Related: #4214

Type of change

  • Bug fix (non-breaking change which fixes an issue)

What's Changed

Hijacks a connection on the connection pool for usage with pg_listen.

Checklist

Changes have been:

  • Tested (unit, integration, or manually with steps specified)
  • Linted and formatted

🤖 AI Disclosure
  • I acknowledge that an LLM was used in the creation of this Pull Request, in accordance with Hatchet's AI_POLICY.md.
  • Details: Claude w/ Fable

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.
@abelanger5
abelanger5 requested a review from Copilot July 22, 2026 15:04
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hatchet-docs Ready Ready Preview, Comment Jul 22, 2026 3:07pm

Request Review

@github-actions github-actions Bot added the engine Related to the core Hatchet engine label Jul 22, 2026

@igor-kupczynski igor-kupczynski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Optional test failure: The load-online-migrate job failed on this PR. This check is non-mandatory and does not block merging, but may be worth investigating. View logs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Connect callback from returning poolConn.Conn() to poolConn.Hijack() to avoid orphaning *pgxpool.Conn wrappers.
  • 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
@abelanger5
abelanger5 merged commit a5e1e36 into main Jul 22, 2026
61 checks passed
@abelanger5
abelanger5 deleted the belanger/fix-listener-pool-leak branch July 22, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine Related to the core Hatchet engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Multiplexed LISTEN connection leaks pool slots on reconnect under server-side idle connection termination

3 participants