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

Fix infinite loop releasing the connection when the writer is not finished #7798

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGES/7798.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix infinite loop releasing the connection when the writer is not finished
16 changes: 14 additions & 2 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,10 +916,12 @@
):
return

self._cleanup_writer()
self._release_connection()
else:
self._cleanup_writer()

Check warning on line 922 in aiohttp/client_reqrep.py

View check run for this annotation

Codecov / codecov/patch

aiohttp/client_reqrep.py#L922

Added line #L922 was not covered by tests

self._closed = True
self._cleanup_writer()

@property
def closed(self) -> bool:
Expand Down Expand Up @@ -968,13 +970,23 @@
headers=self.headers,
)

def _cleanup_on_writer_done(self, _: "asyncio.Future[None]") -> None:
"""Cleanup writer and release connection.

This is called as a callback when the writer finishes
in the event _release_connection was called
before the writer is done.
"""
self._writer = None
self._release_connection()

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_on_writer_done)

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