Skip to content

[Bugfix][Router] Record abandoned requests as aborted in the latency histogram - #1234

Open
Mazyod wants to merge 2 commits into
vllm-project:mainfrom
Mazyod:fix/aborted-request-latency-status
Open

Mazyod wants to merge 2 commits into
vllm-project:mainfrom
Mazyod:fix/aborted-request-latency-status

Conversation

@Mazyod

@Mazyod Mazyod commented Nov 24, 2026

Copy link
Copy Markdown

FIX #1231

A client disconnect reaches process_request as GeneratorExit or asyncio.CancelledError. Neither is an Exception, so request_status stayed "success" and abandoned requests were recorded in vllm:request_latency_seconds as successes. This PR marks them "aborted" and re-raises; the finally block is unchanged.

Testing:

  • test_abandoned_response_is_recorded_as_aborted reads the headers and the first chunk, then closes the generator. It fails on main (status="success" is counted) and passes with this change.
  • All 284 router tests pass on Python 3.12, and pre-commit passes.

  • Make sure the code changes pass the pre-commit checks.
  • Sign-off your commit by using -s when doing git commit
  • Try to classify PRs for easy understanding of the type of changes, such as [Bugfix], [Feat], and [CI].

🤖 Generated with Claude Code

https://claude.ai/code/session_01EkWp1KKx8oCX8JA3mXdkVJ

…histogram

process_request sets request_status = "success" before contacting the
backend and changes it only in `except Exception`. A client disconnect
reaches the generator as GeneratorExit or asyncio.CancelledError. Both are
BaseException, so a response abandoned mid-stream was still observed in
vllm:request_latency_seconds with status="success".

Mark such terminations "aborted" and re-raise. The finally block still
releases the in-flight slot as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EkWp1KKx8oCX8JA3mXdkVJ
Signed-off-by: Mazyad Alabduljaleel <[email protected]>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request ensures that abandoned responses due to client disconnections are correctly recorded as 'aborted' by catching BaseException and setting the request status accordingly. It also adds a test case to verify this behavior. The review feedback suggests adding the @pytest.mark.asyncio decorator to the new asynchronous test to ensure it runs correctly.

assert after_out - before_out == 22


async def test_abandoned_response_is_recorded_as_aborted(monitor):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The async test function test_abandoned_response_is_recorded_as_aborted is missing the @pytest.mark.asyncio decorator. Without this decorator, pytest may not execute it as an asynchronous test, or it might fail depending on the pytest-asyncio configuration. Adding the decorator ensures consistency with the other async tests in this file.

Suggested change
async def test_abandoned_response_is_recorded_as_aborted(monitor):
@pytest.mark.asyncio
async def test_abandoned_response_is_recorded_as_aborted(monitor):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 3b3d56d, to match the other async tests in this file. (asyncio_mode = "auto" already ran it, so the result is unchanged.)

Address review feedback: match the other async tests in this file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EkWp1KKx8oCX8JA3mXdkVJ
Signed-off-by: Mazyad Alabduljaleel <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: requests abandoned by the client are recorded as status="success" in vllm:request_latency_seconds

1 participant