Skip to content

Commit 3181bfd

Browse files
committed
🐛 fixup cancel for v0.6.5
Signed-off-by: Joe Runde <[email protected]>
1 parent 04cafa2 commit 3181bfd

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/vllm_tgis_adapter/grpc/grpc_server.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
extract_trace_headers,
2424
log_tracing_disabled_warning,
2525
)
26-
from vllm.utils import iterate_with_cancellation
2726

2827
from vllm_tgis_adapter.logging import init_logger
2928
from vllm_tgis_adapter.tgis_utils import logs
@@ -262,11 +261,8 @@ async def Generate(
262261
),
263262
)
264263

265-
async def is_cancelled() -> bool:
266-
return context.cancelled()
267-
268264
result_generator: AsyncIterator[tuple[int, RequestOutput]] = (
269-
merge_async_iterators(*generators, is_cancelled=is_cancelled)
265+
merge_async_iterators(*generators)
270266
)
271267

272268
resp_options = request.params.response
@@ -357,11 +353,6 @@ async def GenerateStream( # noqa: PLR0915, C901
357353
**kwargs,
358354
)
359355

360-
async def is_cancelled() -> bool:
361-
return context.cancelled()
362-
363-
result_generator = iterate_with_cancellation(result_generator, is_cancelled)
364-
365356
resp_options = request.params.response
366357

367358
first_response = None

src/vllm_tgis_adapter/tgis_utils/logs.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import asyncio
56
import functools
67
import logging
78
import time
@@ -86,6 +87,12 @@ async def generate_with_logging(*args, **kwargs) -> AsyncGenerator[RequestOutput
8687
async for response in old_generate_fn(*args, **kwargs):
8788
last = response
8889
yield response
90+
except asyncio.CancelledError:
91+
_log_cancellation(
92+
request_id=request_id,
93+
correlation_id=correlation_id,
94+
)
95+
raise
8996
except BaseException as e:
9097
# Log any error
9198
_log_error(
@@ -118,6 +125,14 @@ def _log_error(request_id: str, correlation_id: str, exception_str: str) -> None
118125
)
119126

120127

128+
def _log_cancellation(request_id: str, correlation_id: str) -> None:
129+
logger.info(
130+
"Request cancelled: request_id=%s correlation_id=%s",
131+
request_id,
132+
correlation_id,
133+
)
134+
135+
121136
def _log_request(
122137
request_id: str,
123138
params: SamplingParams,

0 commit comments

Comments
 (0)