asyncpg icon indicating copy to clipboard operation
asyncpg copied to clipboard

Add pool_timeout parameter to prevent pool operation hangs (#431)

Open ermakov-oleg opened this issue 3 months ago • 1 comments

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

ermakov-oleg avatar Sep 23 '25 14:09 ermakov-oleg

Hey @elprans!

What do you think about this change? Would appreciate your input. Thanks!

ermakov-oleg avatar Oct 07 '25 16:10 ermakov-oleg