Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
Description
Bug report
Bug description:
When writing an asyncio based service, you basically have this sequence:
- Create an event loop
- Register a SIGTERM handler
- Start your server
loop.run_forever()
- SIGTERM causes a
loop.stop()
- Close the server
- Close event loop
If there are any connections active at this point, then they don't get discarded until interpreter shutdown, with the result that you get a bunch of ResourceWarnings (and cleanup code might not run).
It would be very useful if there was aServer.close_clients()
or something like that. Even aServer.all_transports()
would be useful, as then you could do something similar as when doing aTask.cancel()
on what you get fromloop.all_tasks()
.
We could poke atServer._transports
, but that is something internal that might change in the future.
There isServer.wait_closed()
, but that hangs until all clients have gracefully disconnected. It doesn't help us when we want to shut down the servicenow.
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
- gh-113538: Don't crash in stream reader protocol callback when task is cancelled #113690
- [3.12] gh-113538: Don't error in stream reader protocol callback when task is cancelled (GH-113690) #113713
- [3.11] gh-113538: Don't error in stream reader protocol callback when task is cancelled (GH-113690) #113714
- gh-113538: Allow client connections to be closed #114432
- gh-113538: Revert "gh-113538: Add asycio.Server.{close,abort}_clients (#114432)" #116632
- gh-113538: Allow client connections to be closed #116784
Metadata
Metadata
Assignees
Projects
Status