[vite-plugin-cloudflare] Handle cancelled request bodies - #15028
Open
harshmathurx wants to merge 2 commits into
Open
[vite-plugin-cloudflare] Handle cancelled request bodies#15028harshmathurx wants to merge 2 commits into
harshmathurx wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: a86640e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
workers-devprod
requested review from
a team and
penalosa
and removed request for
a team
August 5, 2026 03:19
Contributor
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
dario-piotrowicz
requested review from
dario-piotrowicz
and removed request for
penalosa
August 7, 2026 10:24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15027.
This fixes the Vite plugin request bridge so a Worker can intentionally cancel an oversized incoming request body and still return its response instead of surfacing stream-controller errors from the Node request adapter.
The old path used
createRequest()from@remix-run/node-fetch-server, whose request-body stream keeps enqueuingIncomingMessagechunks after the Worker cancels the body reader. In the oversized-body case from the issue, that can surface asInvalid state: Controller is already closed/ transport-level500noise before the Worker response is delivered.This PR keeps the existing URL/header/protocol behavior, but creates the request body stream locally so cancellation detaches the Node request listeners and pauses the incoming request instead of letting later chunks enqueue into a closed controller.
Local verification:
pnpm installNODE_OPTIONS=--max-old-space-size=4096 pnpm test -F @cloudflare/vite-plugin -- utils.spec.tspnpm --filter @cloudflare/vite-plugin exec oxfmt --check src/utils.ts src/__tests__/utils.spec.tsNODE_OPTIONS=--max-old-space-size=4096 pnpm --filter @cloudflare/vite-plugin check:typeNODE_OPTIONS=--max-old-space-size=4096 pnpm --filter @cloudflare/vite-plugin buildNODE_OPTIONS=--max-old-space-size=4096 pnpm --filter @cloudflare/vite-plugin exec oxlint src/utils.ts src/__tests__/utils.spec.ts --deny-warnings --type-awareBefore the fix, the new regression test produced 300 unhandled
TypeError: Invalid state: Controller is already closederrors from@remix-run/node-fetch-serverwhile exercising the Worker-side body cancellation case. After the fix, the focused test file passes cleanly.