Skip to content

Commit 7c273ab

Browse files
[Bugfix]: Fix streaming "connection closed" before body consumed in orchestrated disaggregated routing (#960)
* issues/952: fix streaming connection closed before body consumed in orchestrated disaggregated routing Signed-off-by: shoreline2 <shoreline2@users.noreply.github.com> * Ensure response is released in failure scenarios Signed-off-by: shoreline2 <shoreline2@users.noreply.github.com> * Address pre-commit ruff check Signed-off-by: shoreline2 <shoreline2@users.noreply.github.com> --------- Signed-off-by: shoreline2 <shoreline2@users.noreply.github.com> Co-authored-by: shoreline2 <shoreline2@users.noreply.github.com> Co-authored-by: Rui Zhang <51696593+ruizhang0101@users.noreply.github.com>
1 parent a16f60f commit 7c273ab

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

  • src/vllm_router/services/request_service

src/vllm_router/services/request_service/request.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ async def route_orchestrated_disaggregated_request(
793793

794794
try:
795795
# Use the shared aiohttp client from app state
796-
client = request.app.state.aiohttp_client_wrapper()
796+
client: aiohttp.ClientSession = request.app.state.aiohttp_client_wrapper()
797797

798798
# Send to Prefill
799799
async with client.post(
@@ -842,15 +842,16 @@ async def route_orchestrated_disaggregated_request(
842842
decode_api_url = f"{decode_url}{endpoint}"
843843
logger.info(f"[{request_id}] Sending decode request to {decode_api_url}")
844844

845-
async with client.post(
845+
decode_resp = await client.post(
846846
decode_api_url,
847847
json=decode_request,
848848
headers={
849849
"Content-Type": "application/json",
850850
"X-Request-Id": request_id,
851851
},
852852
timeout=aiohttp.ClientTimeout(total=600),
853-
) as decode_resp:
853+
)
854+
try:
854855
if decode_resp.status != 200:
855856
error_text = await decode_resp.text()
856857
logger.error(
@@ -870,6 +871,7 @@ async def generate_stream():
870871
if chunk:
871872
yield chunk
872873
finally:
874+
decode_resp.release()
873875
curr_time = time.time()
874876
logger.info(
875877
f"[{request_id}] Orchestrated streaming request completed, total time = {curr_time - in_router_time:.4f}s"
@@ -893,6 +895,9 @@ async def generate_stream():
893895
content=json.loads(response_data),
894896
headers={"X-Request-Id": request_id},
895897
)
898+
except Exception:
899+
decode_resp.release()
900+
raise
896901

897902
except aiohttp.ClientError as e:
898903
logger.error(

0 commit comments

Comments
 (0)