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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user