-
Notifications
You must be signed in to change notification settings - Fork 428
[Bugfix]: Fix streaming "connection closed" before body consumed in orchestrated disaggregated routing #960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5a84c2a
03a7aff
b2fb1ae
97c8a74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -793,7 +793,7 @@ async def route_orchestrated_disaggregated_request( | |
|
|
||
| try: | ||
| # Use the shared aiohttp client from app state | ||
| client = request.app.state.aiohttp_client_wrapper() | ||
| client: aiohttp.ClientSession = request.app.state.aiohttp_client_wrapper() | ||
|
|
||
| # Send to Prefill | ||
| async with client.post( | ||
|
|
@@ -842,15 +842,16 @@ async def route_orchestrated_disaggregated_request( | |
| decode_api_url = f"{decode_url}{endpoint}" | ||
| logger.info(f"[{request_id}] Sending decode request to {decode_api_url}") | ||
|
|
||
| async with client.post( | ||
| decode_resp = await client.post( | ||
| decode_api_url, | ||
| json=decode_request, | ||
| headers={ | ||
| "Content-Type": "application/json", | ||
| "X-Request-Id": request_id, | ||
| }, | ||
| timeout=aiohttp.ClientTimeout(total=600), | ||
| ) as decode_resp: | ||
| ) | ||
|
Comment on lines
+845
to
+853
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing the context manager is necessary to fix the premature connection closure for streaming, but it introduces a risk of leaking the Consider wrapping the response handling in a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a
As a result of adding that try/except block, a positive outcome is the diff for this MR becomes much smaller. |
||
| try: | ||
| if decode_resp.status != 200: | ||
| error_text = await decode_resp.text() | ||
| logger.error( | ||
|
|
@@ -870,6 +871,7 @@ async def generate_stream(): | |
| if chunk: | ||
| yield chunk | ||
| finally: | ||
| decode_resp.release() | ||
| curr_time = time.time() | ||
| logger.info( | ||
| f"[{request_id}] Orchestrated streaming request completed, total time = {curr_time - in_router_time:.4f}s" | ||
|
|
@@ -893,6 +895,9 @@ async def generate_stream(): | |
| content=json.loads(response_data), | ||
| headers={"X-Request-Id": request_id}, | ||
| ) | ||
| except Exception: | ||
| decode_resp.release() | ||
| raise | ||
|
|
||
| except aiohttp.ClientError as e: | ||
| logger.error( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason behind adding the typing for this variable is for IDE auto-complete capabilities, where a programmer can see available methods like
release().