GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-79033: Fix asyncio.Server.wait_closed() by gvanrossum · Pull Request #98582 · python/cpython

Conversation

@gvanrossum

@gvanrossum gvanrossum commented Oct 24, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

wait_closed() was a no-op when used as recommended (after close()).

I had to debug one test (test__sock_sendfile_native_failure) -- the cleanup sequence for the test fixture was botched.

Hopefully that's not a portend of problems in user code -- this has never worked so people may well be doing this wrong. :-(

  • Issue: Counter-intuitive behavior of Server.close() / wait_closed() #79033

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gvanrossum
Fix asyncio.Server.wait_closed()
d2eca95
It was a no-op when used as recommended (after close()).

I had to debug one test (test__sock_sendfile_native_failure) --
the cleanup sequence for the test fixture was botched.

Hopefully that's not a portend of problems in user code --
this has never worked so people may well be doing this wrong. :-(
@gvanrossum
gvanrossum requested review from 1st1 and asvetlov as code owners October 24, 2022 02:50
@bedevere-bot bedevere-bot added the awaiting core review label Oct 24, 2022
@gvanrossum

gvanrossum commented Oct 24, 2022

Copy link
Copy Markdown
Member Author

Needs test and news entry

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum
Merge branch 'main' into fix-server-wait-closed
496566c
@bedevere-bot bedevere-bot mentioned this pull request Nov 22, 2022
Counter-intuitive behavior of Server.close() / wait_closed() #79033
Closed
@gvanrossum

gvanrossum commented Nov 22, 2022

Copy link
Copy Markdown
Member Author

@kumaraditya303 Can you suggest a test for this?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@blurb-it
📜🤖 Added by blurb_it.
a9aebfc
@kumaraditya303

kumaraditya303 commented Nov 23, 2022

Copy link
Copy Markdown
Contributor

Something like should work:

diff --git a/Lib/test/test_asyncio/test_server.py b/Lib/test/test_asyncio/test_server.py
index 860d62d52e..ceea4059ae 100644
--- a/Lib/test/test_asyncio/test_server.py
+++ b/Lib/test/test_asyncio/test_server.py
@@ -120,6 +120,26 @@ async def main(srv):
                 self.loop.run_until_complete(srv.serve_forever())
 
 
+class TestServer2(unittest.IsolatedAsyncioTestCase):
+
+    async def test_wait_closed(self):
+        async def serve(*args):
+            pass
+
+        srv = await asyncio.start_server(serve, socket_helper.HOSTv4, 0)
+
+        # active count = 0
+        wait = asyncio.create_task(srv.wait_closed())
+        await asyncio.sleep(0)
+        self.assertTrue(wait.done())
+
+        # active count != 0
+        srv._attach()
+        wait = asyncio.create_task(srv.wait_closed())
+        await asyncio.sleep(0)
+        self.assertFalse(wait.done())
+
+
 @unittest.skipUnless(hasattr(asyncio, 'ProactorEventLoop'), 'Windows only')
 class ProactorStartServerTests(BaseStartServer, unittest.TestCase):
 

Creating a test with an actual client seems rather flaky as it requires a heavy load on server so will be unreliable.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kumaraditya303 kumaraditya303 added the topic-asyncio label Nov 23, 2022
@gvanrossum

gvanrossum commented Nov 23, 2022

Copy link
Copy Markdown
Member Author

Thanks! _attach exists for the transport to indicate that it's active. We should probably also call _detach (after closing the server) and then check that the wait_closed task finishes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum
Add a test (most of it contributed by Kumar)
0b4057a
@gvanrossum
gvanrossum requested a review from kumaraditya303 November 23, 2022 22:46
kumaraditya303
kumaraditya303 approved these changes Nov 24, 2022
View reviewed changes

@kumaraditya303 kumaraditya303 left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM, thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Nov 24, 2022
@gvanrossum
gvanrossum merged commit 5d09d11 into python:main Nov 24, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label Nov 24, 2022
@gvanrossum
gvanrossum deleted the fix-server-wait-closed branch November 24, 2022 15:33
@gvanrossum

gvanrossum commented Nov 24, 2022

Copy link
Copy Markdown
Member Author

Let’s not backport, I fear it will surprise some users since it never worked.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Sep 27, 2023
Fix additional test cases for Python 3.12 home-assistant/core#101006
Merged
TEST: Add 3.12-dev [ci] cdce8p/ha-core#53
Closed
@Dreamsorcerer Dreamsorcerer mentioned this pull request Oct 24, 2023
GH-79033: docs: Minor improvement to asyncio.Server.wait_closed() #111260
Closed
@gvanrossum gvanrossum mentioned this pull request Feb 19, 2024
Abandoned StreamWriter isn't reliably detected #114914
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@kumaraditya303 kumaraditya303 kumaraditya303 approved these changes
@1st1 1st1 Awaiting requested review from 1st1 1st1 is a code owner
@asvetlov asvetlov Awaiting requested review from asvetlov asvetlov is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

topic-asyncio

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@gvanrossum @kumaraditya303 @bedevere-bot
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.