Skip to content

Commit

Permalink
Guard against the unlikely event conn will not be set.
Browse files Browse the repository at this point in the history
  • Loading branch information
iksteen committed Sep 30, 2022
1 parent 0ef6620 commit 1f39c7c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 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 @@ -348,7 +349,8 @@ async def _fill_free_pool(self, override_min: bool) -> None:
self._free.append(conn)
self._cond.notify()
except asyncio.CancelledError:
conn.close()
if conn is not None:
conn.close()
raise
finally:
self._acquiring -= 1
Expand All @@ -357,6 +359,7 @@ async def _fill_free_pool(self, override_min: bool) -> None:

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 @@ -373,7 +376,8 @@ async def _fill_free_pool(self, override_min: bool) -> None:
self._free.append(conn)
self._cond.notify()
except asyncio.CancelledError:
conn.close()
if conn is not None:
conn.close()
raise
finally:
self._acquiring -= 1
Expand Down

0 comments on commit 1f39c7c

Please sign in to comment.