From b6909aa223b18acc1172093f22f8db0ea4365f7f Mon Sep 17 00:00:00 2001 From: ishandhanani <82981111+ishandhanani@users.noreply.github.com> Date: Sat, 17 May 2025 18:32:41 -0700 Subject: [PATCH] fix: allow `launch_dummy_health_check_server` to start inside of running asyncio loop (#6330) --- python/sglang/srt/utils.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/python/sglang/srt/utils.py b/python/sglang/srt/utils.py index 9cbea8252..828b23039 100644 --- a/python/sglang/srt/utils.py +++ b/python/sglang/srt/utils.py @@ -1847,6 +1847,8 @@ def get_cuda_version(): def launch_dummy_health_check_server(host, port): + import asyncio + import uvicorn from fastapi import FastAPI, Response @@ -1862,13 +1864,27 @@ def launch_dummy_health_check_server(host, port): """Check the health of the http server.""" return Response(status_code=200) - uvicorn.run( + config = uvicorn.Config( app, host=host, port=port, timeout_keep_alive=5, - loop="uvloop", + loop="auto", + log_config=None, + log_level="warning", ) + server = uvicorn.Server(config=config) + + try: + loop = asyncio.get_running_loop() + logger.info( + f"Dummy health check server scheduled on existing loop at {host}:{port}" + ) + loop.create_task(server.serve()) + + except RuntimeError: + logger.info(f"Starting dummy health check server at {host}:{port}") + server.run() def create_checksum(directory: str):