Repository navigation
Conversation
Python 3.13 added close_clients() and abort_clients() to asyncio.Server, to close (or abort) the connections accepted by a server, but uvloop.loop.Server did not have them and raised AttributeError. Keep track of the server's client transports in a WeakSet (as asyncio does) next to the existing active connection count, and implement both methods on top of it. Fixes MagicStack#683.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #683.
Python 3.13 added
Server.close_clients()andServer.abort_clients()to asyncio, butuvloop.loop.Serverdoesn't have them:AttributeError: 'uvloop.loop.Server' object has no attribute 'close_clients'.The server now keeps its client transports in a
WeakSet(as asyncio'sServer._clientsdoes), next to the existing_active_count._attach()/_detach()take the transport, and the two new methods callclose()/abort()on a snapshot of that set. The methods exist on every Python version uvloop supports, not just 3.13+.wait_closed()keeps its current behaviour.Tests:
test_server_close_clients/test_server_abort_clientsintests/test_tcp.pystart a server with three connected clients and callsrv.close(). They check that the connections stay open, then call the new method and check that every client sees EOF (or a reset forabort_clients) and every handler finishes. The asyncio variants are skipped before 3.13.Testing (macOS arm64, built with
--use-system-libuvagainst Homebrew libuv 1.53.0):master, bothTest_UV_TCPtests fail on 3.13:AttributeError: 'uvloop.loop.Server' object has no attribute 'close_clients'(and the same forabort_clients). TheTest_AIO_TCPvariants pass.python -m unittest discover testson 3.12 and 3.13, and withPYTHONASYNCIODEBUG=1on 3.13: 531 tests each. The only failure istest_fs_event_rename(FSEvents reports CHANGE instead of RENAME on this machine). It fails the same way in a tree without this change.Not run: Linux, the free-threaded build, the bundled-libuv build, and benchmarks. The accept path now does one
WeakSet.add()and onediscard()per connection.