code: async def on_shutdown(app):
      
      global is_shutting_down
      is_shutting_down = True
      for task in app["websockets"]:
          task.cancel()
          try:
              await task
          except asyncio.CancelledError:
              pass
docs: Closes all WS connections on shutdown.