Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions aiopg/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ async def _fill_free_pool(self, override_min: bool) -> None:

while self.size < self.minsize:
self._acquiring += 1
conn = None
try:
conn = await connect(
self._dsn,
Expand All @@ -347,13 +348,18 @@ async def _fill_free_pool(self, override_min: bool) -> None:
# raise exception if pool is closing
self._free.append(conn)
self._cond.notify()
except asyncio.CancelledError:
if conn is not None:
conn.close()
raise
finally:
self._acquiring -= 1
if self._free:
return

if override_min and (not self.maxsize or self.size < self.maxsize):
self._acquiring += 1
conn = None
try:
conn = await connect(
self._dsn,
Expand All @@ -369,6 +375,10 @@ async def _fill_free_pool(self, override_min: bool) -> None:
# raise exception if pool is closing
self._free.append(conn)
self._cond.notify()
except asyncio.CancelledError:
if conn is not None:
conn.close()
raise
finally:
self._acquiring -= 1

Expand Down