Skip to content

[Router][Bugfix] Propagate client cancellation - #12

Merged
Levi080513 merged 2 commits into
neutree-ai:neutreefrom
Levi080513:neu916-pick-cancellation
Nov 26, 2026
Merged

Levi080513 merged 2 commits into
neutree-ai:neutreefrom
Levi080513:neu916-pick-cancellation

Conversation

@Levi080513

@Levi080513 Levi080513 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

When a client disconnected while the Router was waiting for backend response headers or a connection-pool slot, the pending backend request could remain alive. It could reach the backend after the client had aborted, while Router request statistics and pool state remained occupied.

Change

  • Race the initial backend response wait against ASGI http.disconnect.
  • Cancel and await the pending backend generator when the client disconnects, with cancellation protection for cleanup.
  • Return HTTP 499 when the client disconnects before backend headers are available.
  • Explicitly close the backend generator when response sending fails or is cancelled.
  • Keep existing API test requests connected until an explicit disconnect event.
  • Cover queued cancellation, pool and request-state recovery, cancellation propagation, and response cleanup during send failures or disconnects under backpressure.

This adapts the behavior proposed by upstream production-stack PR vllm-project#1040 to the Neutree fork. The upstream PR is not merged. The fork's existing request-statistics cleanup is retained.

Test plan

Unit test

  • Python 3.12.13: PYTHONPATH=src python -m pytest -q src/tests — 105 passed.
  • Queue regression: a real aiohttp connection pool with one occupied slot returns to holder-only state after cancellation. The cancelled request does not reach the backend after the holder is released, and a recovery request succeeds.
  • Response cleanup: directly exercise the response with ASGI 2.3 disconnects during backpressure and ASGI 2.3/2.4 send errors. Assert backend-context exit and request-statistics cleanup.
  • Confirmed the queue regression fails without cancellation propagation and all three response-cleanup cases fail with ordinary StreamingResponse.
  • pre-commit run --files src/vllm_router/services/request_service/request.py src/tests/test_client_disconnect.py src/tests/test_inference_api_routes.py src/tests/test_request_stats.py — passed.
  • The unit-test run reports the existing missing generated vllm_router._version warning; no test failures.

DB test

  • Not applicable: no database or schema changes.

E2E test

  • Not run against a deployed Router. The release-image cancellation regression remains to be verified.
  • No additional manual testing is needed for the test-fixture changes.

@Levi080513
Levi080513 changed the base branch from main to neutree November 26, 2026 10:22
@Levi080513
Levi080513 marked this pull request as ready for review November 26, 2026 14:04
@Levi080513
Levi080513 merged commit aea09b1 into neutree-ai:neutree Nov 26, 2026
9 of 10 checks passed
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.

1 participant