Skip to content

Conversation

@cofin
Copy link
Member

@cofin cofin commented Jan 27, 2026

Fixes #346.

Implements double-checked locking in AsyncDatabaseConfig and SyncDatabaseConfig to ensure thread-safe and coroutine-safe pool initialization.

This prevents the issue where concurrent calls to provide_pool() (or implicit pool creation via session/connection provision) could create multiple pool instances, leading to 'invalid connection' errors when releasing connections.

Added tests/integration/test_pool_concurrency.py which reliably reproduces the race condition (failing before this fix) and verifies the fix.

Implements double-checked locking in AsyncDatabaseConfig and SyncDatabaseConfig to prevent multiple pools from being created when provide_pool is called concurrently.

Fixes #346
@cofin cofin merged commit 7e8af3e into main Jan 27, 2026
11 checks passed
@cofin cofin deleted the fix/pool-concurrency-race-condition branch January 27, 2026 16:00
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.

Fix race condition in connection pool initialization

2 participants