Skip to content

[PR] fix: cancel rejected continuation response bodies - #7171

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-18_release-continuation-error-body
Nov 20, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-18_release-continuation-error-body

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Fixes #7170

Problem

A rejected continuation returns null to preserve the existing fallback, but its non-429 branch clears the fetch watchdog without consuming or canceling the upstream response body. A server that sends an error chunk and leaves the response open retains that transport connection with no remaining consumer.

The real HTTP regression uses an undici Agent with one connection: on unchanged master, the next request never reaches the server and its 1,500 ms watchdog aborts. The server has received one request and its unfinished 503 response is still open.

Change

Cancel the discarded non-429 body after the existing throttle and timer cleanup. Fire-and-forget cancellation keeps the fallback responsive even if a transport rejects cancellation or a tee sibling never finishes. Successful continuation streams remain owned by their caller; 429 responses remain owned by the bounded reader that refines model-specific holds.

The fixed real HTTP test receives both requests, observes the old 503 response close, and reads the next response in full. The change applies to the shared continuation helper in plugin and proxy pass-through lanes, independently of compression mode. It does not change retry decisions, request bytes, model-facing text, configuration, kernel code or response framing.

Validation

Tested on bili 0.1.216, Node 24.22.1, base 548e396022b9391e28a3c9061560be297779b8e8 (current master when checked).

  • Nine new tests: 302/403/503 unfinished bodies; rejecting and never-settling cancellation; successful byte-exact streaming; bodyless responses; 429 model-scope classification; and a real HTTP server with a one-connection pool.
  • Unchanged master: 6 failed, 3 passed. The real server records {requests: 1, rejectedResponseClosed: false} before cleanup.
  • Fixed new tests plus the existing 429 continuation, plugin empty-turn retry and client-abort lifetime suites: 41 passed, 0 skipped. The real server records {requests: 2, rejectedResponseClosed: true}.
  • Typecheck, full build including import/external dependency guards, test import-graph check and git diff --check pass.
  • Independent read-only review checked both body owners and non-blocking cancellation; no blocking finding. The full repository suite was not run locally; remote full-suite regression is not yet verified.

Prior work

Screened all 258 pre-existing fork heads: this module has one complete fork version and no discarded non-429 body cancellation. All 12 upstream module revisions (four rejection-branch variants) also lack it. #6630 changes compress-loop response ownership; #1072 preserves client aborts for successful spliced streams. Their actual diffs do not fix this rejection path.

Release non-429 response bodies when the continuation is discarded.
Keep cancellation asynchronous so an unfinished tee sibling cannot delay
the existing null fallback; preserve successful streams and 429 readers.
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.

Rejected continuation retries leave unfinished response bodies and connections open

2 participants