Skip to content

Commit

Permalink
[PR #8636/51d872e backport][3.10] Remove Request.wait_for_disconnecti…
Browse files Browse the repository at this point in the history
…on() method (#8650)

Co-authored-by: Sam Bull <git@sambull.org>
  • Loading branch information
bdraco and Dreamsorcerer authored Aug 8, 2024
1 parent 1f92213 commit 6a77806
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 30 deletions.
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`.
27 changes: 10 additions & 17 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 Down Expand Up @@ -50,7 +49,6 @@
reify,
sentinel,
set_exception,
set_result,
)
from .http_parser import RawRequestMessage
from .http_writer import HttpVersion
Expand Down Expand Up @@ -146,7 +144,6 @@ class BaseRequest(MutableMapping[str, Any], HeadersMixin):
"_loop",
"_transport_sslcontext",
"_transport_peername",
"_disconnection_waiters",
]
)

Expand Down Expand Up @@ -194,7 +191,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 @@ -823,21 +819,18 @@ 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()

async def wait_for_disconnection(self) -> None:
loop = asyncio.get_event_loop()
fut = loop.create_future() # type: asyncio.Future[None]
self._disconnection_waiters.add(fut)
try:
await fut
finally:
self._disconnection_waiters.remove(fut)
if self._post is None or self.content_type != "multipart/form-data":
return

# NOTE: Release file descriptors for the
# NOTE: `tempfile.Temporaryfile`-created `_io.BufferedRandom`
# 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 isinstance(file_field_object, FileField):
file_field_object.file.close()


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

.. method:: wait_for_disconnection()

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:: 3.10

.. class:: Request

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

0 comments on commit 6a77806

Please sign in to comment.