Skip to content

Commit

Permalink
Fix infinite loop releasing the connection when the writer is not fin…
Browse files Browse the repository at this point in the history
…ished

aio-libs#7764 ensured the connection was released if the writer was
not done yet, but it never cleared the writer so it would
schedule callbacks in a loop
  • Loading branch information
bdraco committed Nov 7, 2023
1 parent 54a0d9a commit 86b741d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,13 +968,26 @@ def raise_for_status(self) -> None:
headers=self.headers,
)

def _cleanup_writer_and_release_connection(self, _: asyncio.Future) -> None:
"""Cleanup writer and release connection.
This is called when the writer is not finished
and _release_connection is called.
"""
if self._connection is not None:
self._cleanup_writer()
self._connection.release()
self._connection = None

def _release_connection(self) -> None:
if self._connection is not None:
if self._writer is None:
self._connection.release()
self._connection = None
else:
self._writer.add_done_callback(lambda f: self._release_connection())
self._writer.add_done_callback(
self._cleanup_writer_and_release_connection
)

async def _wait_released(self) -> None:
if self._writer is not None:
Expand Down

0 comments on commit 86b741d

Please sign in to comment.