Add some backup checks when stopping maubot

This commit is contained in:
Tulir Asokan 2018-11-11 21:20:50 +02:00
parent 20a9ca6aa6
commit 6f2162d5f3
3 changed files with 10 additions and 3 deletions

View File

@ -90,7 +90,10 @@ except KeyboardInterrupt:
log.debug("Closing websockets") log.debug("Closing websockets")
loop.run_until_complete(stop_management_api()) loop.run_until_complete(stop_management_api())
log.debug("Stopping server") log.debug("Stopping server")
loop.run_until_complete(server.stop()) try:
loop.run_until_complete(asyncio.wait_for(server.stop(), 5, loop=loop))
except asyncio.TimeoutError:
log.warning("Stopping server timed out")
log.debug("Closing event loop") log.debug("Closing event loop")
loop.close() loop.close()
log.debug("Everything stopped, shutting down") log.debug("Everything stopped, shutting down")

View File

@ -72,7 +72,7 @@ sockets = []
async def stop_all() -> None: async def stop_all() -> None:
for socket in sockets: for socket in sockets:
try: try:
await socket.close(1012) await socket.close(code=1012)
except Exception: except Exception:
pass pass
@ -106,6 +106,9 @@ async def log_websocket(request: web.Request) -> web.WebSocketResponse:
await ws.send_json({"auth_success": True}) await ws.send_json({"auth_success": True})
elif not authenticated: elif not authenticated:
await ws.send_json({"auth_success": False}) await ws.send_json({"auth_success": False})
except Exception:
try:
await ws.close()
except Exception: except Exception:
pass pass
log_root.removeHandler(handler) log_root.removeHandler(handler)

View File

@ -99,6 +99,7 @@ class MaubotServer:
self.log.info(f"Listening on {site.name}") self.log.info(f"Listening on {site.name}")
async def stop(self) -> None: async def stop(self) -> None:
await self.runner.shutdown()
await self.runner.cleanup() await self.runner.cleanup()
@staticmethod @staticmethod