Skip to content

Commit 375a445

Browse files
committed
Use asyncio.wait_for in pool acquire regardless of timeout
When wait_for is called with timeout=None, it runs without a timeout, as desired
1 parent 6f22ad8 commit 375a445

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

asyncpg/pool.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -614,20 +614,18 @@ def _release_leaked_connection(fut):
614614
self._check_init()
615615

616616
acquire_fut = asyncio.ensure_future(_acquire_impl())
617-
if timeout is None:
618-
return await acquire_fut
619-
else:
620-
try:
621-
return await asyncio.wait_for(
622-
acquire_fut, timeout=timeout)
623-
except asyncio.CancelledError:
624-
# Ensure connection is marked as not in use.
625-
# The cancellation may have raced the acquire, leading
626-
# to the acquire completing but the wait_for to be
627-
# cancelled.
628-
# See: https://bugs.python.org/issue37658
629-
acquire_fut.add_done_callback(_release_leaked_connection)
630-
raise
617+
try:
618+
# Calling wait_for with timeout=None will shortcut to run without timeout
619+
return await asyncio.wait_for(
620+
acquire_fut, timeout=timeout)
621+
except asyncio.CancelledError:
622+
# Ensure connection is marked as not in use.
623+
# The cancellation may have raced the acquire, leading
624+
# to the acquire completing but the wait_for to be
625+
# cancelled.
626+
# See: https://bugs.python.org/issue37658
627+
acquire_fut.add_done_callback(_release_leaked_connection)
628+
raise
631629

632630
async def release(self, connection, *, timeout=None):
633631
"""Release a database connection back to the pool.

0 commit comments

Comments
 (0)