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")
loop.run_until_complete(stop_management_api())
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")
loop.close()
log.debug("Everything stopped, shutting down")

View File

@ -72,7 +72,7 @@ sockets = []
async def stop_all() -> None:
for socket in sockets:
try:
await socket.close(1012)
await socket.close(code=1012)
except Exception:
pass
@ -107,7 +107,10 @@ async def log_websocket(request: web.Request) -> web.WebSocketResponse:
elif not authenticated:
await ws.send_json({"auth_success": False})
except Exception:
pass
try:
await ws.close()
except Exception:
pass
log_root.removeHandler(handler)
log.debug(f"Connection from {request.remote} closed")
sockets.remove(ws)

View File

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