refactor: use AsyncExitStack for aiohttp runner cleanup

Replace try/finally with contextlib.AsyncExitStack for cleaner
structured cleanup of the aiohttp runner. This ensures proper
resource cleanup even in complex shutdown scenarios.

Addresses REFACTORING.md item about TaskGroup/cleanup context.
This commit is contained in:
GitHub Copilot
2026-01-24 10:24:23 +00:00
parent f2996c2d9e
commit 48247d35c7
+3 -3
View File
@@ -298,8 +298,10 @@ class LocalServer:
app.add_routes(self._build_routes())
runner = web.AppRunner(app)
try:
async with contextlib.AsyncExitStack() as stack:
await runner.setup()
stack.push_async_callback(runner.cleanup)
site = web.TCPSite(runner, self.host, self.port)
await site.start()
@@ -307,8 +309,6 @@ class LocalServer:
log.info("Available apps: %s", ", ".join(app.name for app in self.session_manager.apps))
await self.exit_event.wait()
finally:
await runner.cleanup()
async def _dispatch_ws_message(
self,