fix(entrypoints): stop resolve_items leaking in-flight media fetch tasks on partial failure (#48333)
Signed-off-by: ErenAta16 <erena6466@gmail.com>
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import asyncio
|
||||
import warnings
|
||||
from collections.abc import Mapping
|
||||
from typing import Literal
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
@@ -13,6 +15,7 @@ from vllm.assets.image import ImageAsset
|
||||
from vllm.assets.video import VideoAsset
|
||||
from vllm.config import ModelConfig
|
||||
from vllm.entrypoints.chat_utils import (
|
||||
AsyncMultiModalItemTracker,
|
||||
ConversationMessage,
|
||||
_postprocess_messages,
|
||||
parse_chat_messages,
|
||||
@@ -2742,3 +2745,39 @@ def test_postprocess_messages_null_arguments_string():
|
||||
tool_calls = messages[0]["tool_calls"]
|
||||
assert tool_calls is not None
|
||||
assert tool_calls[0]["function"]["arguments"] == {}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_items_does_not_leak_tasks_on_partial_failure():
|
||||
"""Regression test: one failing media fetch must not abandon the other
|
||||
still-in-flight fetches in the same modality batch.
|
||||
|
||||
Before the fix, `resolve_items` gathered per-modality fetches with plain
|
||||
`asyncio.gather`, so the first exception propagated immediately while
|
||||
sibling fetches (real network/thread-pool work in production) kept
|
||||
running detached, with nothing left to await or cancel them.
|
||||
"""
|
||||
|
||||
async def _fetch(should_fail: bool, delay: float):
|
||||
if should_fail:
|
||||
await asyncio.sleep(0.01)
|
||||
raise ValueError("simulated fetch failure")
|
||||
await asyncio.sleep(delay)
|
||||
return ("decoded", None)
|
||||
|
||||
tracker = AsyncMultiModalItemTracker(MagicMock())
|
||||
tracker._items_by_modality["image"] = [
|
||||
lambda: _fetch(True, 0),
|
||||
lambda: _fetch(False, 0.2),
|
||||
lambda: _fetch(False, 0.2),
|
||||
]
|
||||
|
||||
tasks_before = asyncio.all_tasks()
|
||||
with pytest.raises(ValueError, match="simulated fetch failure"):
|
||||
await tracker.resolve_items()
|
||||
|
||||
leaked_tasks = asyncio.all_tasks() - tasks_before
|
||||
assert not leaked_tasks, (
|
||||
f"resolve_items left {len(leaked_tasks)} task(s) running after "
|
||||
f"raising: {leaked_tasks}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user