Skip to content

fix: use _PooledConnection wrapper instead of reassigning conn.close - #36

Merged
surrealwolf merged 2 commits into
mainfrom
fix/pooled-connection-wrapper
Feb 9, 2026
Merged

fix: use _PooledConnection wrapper instead of reassigning conn.close#36
surrealwolf merged 2 commits into
mainfrom
fix/pooled-connection-wrapper

Conversation

@surrealwolf

Copy link
Copy Markdown
Collaborator

Summary

Fixes poller "connection pool exhausted" and 'psycopg2.extensions.connection' object attribute 'close' is read-only errors.

Problem

The code reassigned conn.close = _close so that calling close() would return the connection to the pool instead of closing it. In psycopg2, conn.close is read-only, causing AttributeError and connections never being returned to the pool.

Solution

Introduce _PooledConnection wrapper that:

  • Delegates to the real connection via __getattr__
  • Overrides close() to call putconn() instead of closing the connection

Deploy

Requires new image build (e.g. v0.24) after merge.

conn.close is read-only in psycopg2, causing AttributeError and connections
never returned to pool. Wrapper delegates to real connection and overrides
close() to putconn() instead of closing.

Co-authored-by: Cursor <cursoragent@cursor.com>
_PooledConnection had incorrectly absorbed Database methods. Restore
correct structure: _PooledConnection only has close/__getattr__, Database
has the rest.

Co-authored-by: Cursor <cursoragent@cursor.com>
@surrealwolf
surrealwolf merged commit 19e08ca into main Feb 9, 2026
8 checks passed
@surrealwolf
surrealwolf deleted the fix/pooled-connection-wrapper branch February 9, 2026 07:41
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.

1 participant