Skip to content

gh-113538: Allow client connections to be closed #114432

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

Merged
merged 14 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions Doc/library/asyncio-eventloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,9 @@ Do not instantiate the :class:`Server` class directly.
Calls :meth:`~asyncio.BaseTransport.close` on all associated
transports.

:meth:`close` should be called before :meth:`close_clients` when
closing the server to avoid races with new clients connecting.

.. versionadded:: 3.13

.. method:: abort_clients()
Expand All @@ -1658,6 +1661,9 @@ Do not instantiate the :class:`Server` class directly.
Calls :meth:`~asyncio.WriteTransport.abort` on all associated
transports.

:meth:`close` should be called before :meth:`abort_clients` when
closing the server to avoid races with new clients connecting.

.. versionadded:: 3.13

.. method:: get_loop()
Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ asyncio
(Contributed by Pierre Ossman in :gh:`111246`.)

* Add :meth:`asyncio.Server.close_clients` and
:meth:`asyncio.Server.abort_clients` methods which allows to more
:meth:`asyncio.Server.abort_clients` methods which allow to more
forcefully close an asyncio server.
(Contributed by Pierre Ossman in :gh:`113538`.)

Expand Down
3 changes: 1 addition & 2 deletions Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ def _attach(self, transport):
def _detach(self, transport):
# Note that 'transport' may already be missing from
# self._clients if it has been garbage collected
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO you don't need this comment either (it was explaining the condition).

if transport in self._clients:
self._clients.remove(transport)
self._clients.discard(transport)
if len(self._clients) == 0 and self._sockets is None:
self._wakeup()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Add :meth:`asyncio.Server.close_clients` and
:meth:`asyncio.Server.abort_clients` methods which allows to more forcefully
:meth:`asyncio.Server.abort_clients` methods which allow to more forcefully
close an asyncio server.