Skip to content

fix connection closed issue#3

Merged
davidgilady merged 2 commits intomainfrom
david.g/fix_connection_closed_issue
Feb 22, 2026
Merged

fix connection closed issue#3
davidgilady merged 2 commits intomainfrom
david.g/fix_connection_closed_issue

Conversation

@davidgilady
Copy link
Owner

No description provided.

- Remove blanket pool invalidation from SqlDriver.execute_query() error handler
- Pool connections are managed by psycopg_pool which handles broken connections internally
- Blindly invalidating the pool on every error races with concurrent in-flight queries
- Update test to reflect corrected behavior: query errors no longer invalidate pool
… closed' errors

When multiple MCP tool calls arrive simultaneously, concurrent coroutines
could all see the pool as invalid and enter pool_connect(), each closing
the pool the previous caller just created. This cascaded into repeated
'the pool pool-N is closed' and 'NoneType has no attribute connection'
errors.

Add asyncio.Lock with double-checked locking to both DbConnPool.pool_connect()
and DatabaseService.get_sql_driver() so only one coroutine creates the pool
while others wait and reuse it. Also reset db_connection to None on failed
connection attempts to allow proper retry.
@davidgilady davidgilady merged commit a7b45cf into main Feb 22, 2026
1 check passed
@davidgilady davidgilady deleted the david.g/fix_connection_closed_issue branch February 24, 2026 23:21
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