gh-79033: Try to fix asyncio.Server.wait_closed() again#111336
Merged
willingc merged 2 commits intopython:mainfrom Oct 28, 2023
Merged
gh-79033: Try to fix asyncio.Server.wait_closed() again#111336willingc merged 2 commits intopython:mainfrom
willingc merged 2 commits intopython:mainfrom
Conversation
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.
I identified the condition that
wait_closed()is intended to wait for: the server is closed and there are no more active connections.When this condition first becomes true,
_wakeup()is called (either fromclose()or from_detach()) and it sets_waiterstoNone. So we just check forself._waiters is None; if it's notNone, we know we have to wait, and do so.A problem was that the new test introduced in 3.12 explicitly tested that
wait_closed()returns immediately when the server is not closed but there are currently no active connections. This was a mistake (probably a misunderstanding of the intended semantics). I've fixed the test, and added a separate test that checks exactly for this scenario.I also fixed an oddity where in
_wakeup()the result of the waiter was set to the waiter itself. This result is not used anywhere and I changed this toNone, to avoid a GC cycle.📚 Documentation preview 📚: https://cpython-previews--111336.org.readthedocs.build/