Skip to content

Fix connection pool leak in Listener.Connect on afterConnectExec failure#1147

Merged
brandur merged 1 commit intoriverqueue:masterfrom
GiGurra:fix/listener-connect-pool-leak
Feb 15, 2026
Merged

Fix connection pool leak in Listener.Connect on afterConnectExec failure#1147
brandur merged 1 commit intoriverqueue:masterfrom
GiGurra:fix/listener-connect-pool-leak

Conversation

@GiGurra
Copy link
Contributor

@GiGurra GiGurra commented Feb 13, 2026

Summary

  • When afterConnectExec fails in Listener.Connect(), the acquired pool connection is not released back to the pool, causing a connection leak
  • The QueryRow error path 10 lines below already correctly calls poolConn.Release(), but the Exec error path was missing it
  • Added a test that creates a pool with MaxConns=1, sets afterConnectExec to invalid SQL, and verifies the connection is returned to the pool after the error (without the fix, a subsequent Acquire hangs forever)

Test plan

  • New test TestListener_Connect/ReleasesPoolConnOnAfterConnectExecError verifies the fix (fails without it, passes with it)
  • New test TestListener_Connect/SuccessfulConnect verifies normal connect still works
  • Existing test suite passes

🤖 Generated with Claude Code

When afterConnectExec fails (used for setting custom schema search
paths), the acquired pool connection was not released back to the pool.
This could deplete the connection pool on repeated reconnection failures.

The QueryRow error path 10 lines below already had the correct
poolConn.Release() call, but the Exec path was missing it.

The test creates a pool with MaxConns=1 and sets afterConnectExec to
invalid SQL. Without the fix, a subsequent Acquire blocks forever
because the single connection was leaked.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@brandur brandur merged commit 422df4c into riverqueue:master Feb 15, 2026
21 of 22 checks passed
brandur added a commit that referenced this pull request Feb 15, 2026
Adds changelog entries for #1147, #1148, and #1149.

Also make a couple small tweaks: one to alphabetize a newly added
property, and one to move a success case test to above the error case,
which is a little more conventional.
brandur added a commit that referenced this pull request Feb 15, 2026
Adds changelog entries for #1147, #1148, and #1149.

Also make a couple small tweaks: one to alphabetize a newly added
property, and one to move a success case test to above the error case,
which is a little more conventional.
brandur added a commit that referenced this pull request Feb 15, 2026
Adds changelog entries for #1147, #1148, #1149, and #1150.

Also make a couple small tweaks: one to alphabetize a newly added
property, and one to move a success case test to above the error case,
which is a little more conventional.
brandur added a commit that referenced this pull request Feb 15, 2026
#1151)

Adds changelog entries for #1147, #1148, #1149, and #1150.

Also make a couple small tweaks: one to alphabetize a newly added
property, and one to move a success case test to above the error case,
which is a little more conventional.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants