Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close connection when _fill_free_pool is cancelled. #893

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
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