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

Remove Request.wait_for_disconnection() method #8636

Merged
merged 6 commits into from
Aug 8, 2024
Merged
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/8636.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed ``Request.wait_for_disconnection()`` which was mistakenly added briefly in 3.10.0 -- by :user:`Dreamsorcerer`.
24 changes: 2 additions & 22 deletions aiohttp/web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
MutableMapping,
Optional,
Pattern,
Set,
Tuple,
Union,
cast,
Expand All @@ -43,7 +42,6 @@
reify,
sentinel,
set_exception,
set_result,
)
from .http_parser import RawRequestMessage
from .http_writer import HttpVersion
Expand Down Expand Up @@ -141,7 +139,6 @@ class BaseRequest(MutableMapping[str, Any], HeadersMixin):
"_loop",
"_transport_sslcontext",
"_transport_peername",
"_disconnection_waiters",
"__weakref__",
)

Expand Down Expand Up @@ -190,7 +187,6 @@ def __init__(
self._task = task
self._client_max_size = client_max_size
self._loop = loop
self._disconnection_waiters: Set[asyncio.Future[None]] = set()

transport = self._protocol.transport
assert transport is not None
Expand Down Expand Up @@ -817,13 +813,8 @@ async def _prepare_hook(self, response: StreamResponse) -> None:

def _cancel(self, exc: BaseException) -> None:
set_exception(self._payload, exc)
for fut in self._disconnection_waiters:
set_result(fut, None)

def _finish(self) -> None:
for fut in self._disconnection_waiters:
fut.cancel()

if self._post is None or self.content_type != "multipart/form-data":
return

Expand All @@ -832,19 +823,8 @@ def _finish(self) -> None:
# NOTE: instances of files sent within multipart request body
# NOTE: via HTTP POST request.
for file_name, file_field_object in self._post.items():
if not isinstance(file_field_object, FileField):
continue

file_field_object.file.close()

async def wait_for_disconnection(self) -> None:
loop = asyncio.get_event_loop()
fut: asyncio.Future[None] = loop.create_future()
self._disconnection_waiters.add(fut)
try:
await fut
finally:
self._disconnection_waiters.remove(fut)
if isinstance(file_field_object, FileField):
file_field_object.file.close()


class Request(BaseRequest):
Expand Down
14 changes: 0 additions & 14 deletions docs/web_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -490,20 +490,6 @@ and :ref:`aiohttp-web-signals` handlers.
required work will be processed by :mod:`aiohttp.web`
internal machinery.

.. method:: wait_for_disconnection()
:async:

Returns when the connection that sent this request closes

If there is no client disconnection during request handling, this
coroutine gets cancelled automatically at the end of this request being
handled.

This can be used in handlers as a means of receiving a notification of
premature client disconnection.

.. versionadded:: 4.0

.. class:: Request

A request used for receiving request's information by *web handler*.
Expand Down
Loading