asyncpg
asyncpg copied to clipboard
Add pool_timeout parameter to prevent pool operation hangs (#431)
Summary
Adds pool_timeout parameter to Pool and create_pool() to prevent indefinite hangs in pool operations.
Problem
Pool operations could hang indefinitely, particularly during connection cleanup and cancellation (issue #431).
Solution
pool = await asyncpg.create_pool(dsn, pool_timeout=5.0)
# Now safe to call without explicit timeouts
result = await pool.fetch("SELECT 1")
conn = await pool.acquire() # Uses pool_timeout as fallback
Changes
- Added pool_timeout parameter with validation (must be > 0 or None)
- Fallback logic: explicit timeout → pool_timeout → infinite wait
- Pool convenience methods (fetch, execute, etc.) now respect pool_timeout
- Full backward compatibility maintained
Hey @elprans!
What do you think about this change? Would appreciate your input. Thanks!