Skip to content

Commit 9043f78

Browse files
authored
[BugFix] Prevent the task of _force_log from being garbage collected
The task returned by `asyncio.create_task` should not be discarded. See python/cpython#88831
1 parent 0f8a914 commit 9043f78

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

vllm/entrypoints/openai/api_server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
openai_serving_completion: OpenAIServingCompletion
3434
logger = init_logger(__name__)
3535

36+
_running_tasks = set()
3637

3738
@asynccontextmanager
3839
async def lifespan(app: fastapi.FastAPI):
@@ -43,7 +44,9 @@ async def _force_log():
4344
await engine.do_log_stats()
4445

4546
if not engine_args.disable_log_stats:
46-
asyncio.create_task(_force_log())
47+
task = asyncio.create_task(_force_log())
48+
_running_tasks.add(task)
49+
task.add_done_callback(_running_tasks.remove)
4750

4851
yield
4952

0 commit comments

Comments
 (0)