Skip to content

[vite-plugin-cloudflare] Handle cancelled request bodies - #15028

Open
harshmathurx wants to merge 2 commits into
cloudflare:mainfrom
harshmathurx:jeeves/repro-vite-body-cancel-race
Open

[vite-plugin-cloudflare] Handle cancelled request bodies#15028
harshmathurx wants to merge 2 commits into
cloudflare:mainfrom
harshmathurx:jeeves/repro-vite-body-cancel-race

Conversation

@harshmathurx

@harshmathurx harshmathurx commented Aug 5, 2026

Copy link
Copy Markdown

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 enqueuing IncomingMessage chunks after the Worker cancels the body reader. In the oversized-body case from the issue, that can surface as Invalid state: Controller is already closed / transport-level 500 noise 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.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: this is a local dev transport bug fix covered by a regression test.

Local verification:

  • pnpm install
  • NODE_OPTIONS=--max-old-space-size=4096 pnpm test -F @cloudflare/vite-plugin -- utils.spec.ts
  • pnpm --filter @cloudflare/vite-plugin exec oxfmt --check src/utils.ts src/__tests__/utils.spec.ts
  • NODE_OPTIONS=--max-old-space-size=4096 pnpm --filter @cloudflare/vite-plugin check:type
  • NODE_OPTIONS=--max-old-space-size=4096 pnpm --filter @cloudflare/vite-plugin build
  • NODE_OPTIONS=--max-old-space-size=4096 pnpm --filter @cloudflare/vite-plugin exec oxlint src/utils.ts src/__tests__/utils.spec.ts --deny-warnings --type-aware

Before the fix, the new regression test produced 300 unhandled TypeError: Invalid state: Controller is already closed errors from @remix-run/node-fetch-server while exercising the Worker-side body cancellation case. After the fix, the focused test file passes cleanly.


Open in Devin Review

@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a86640e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/vite-plugin Patch

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
workers-devprod requested review from a team and penalosa and removed request for a team August 5, 2026 03:19
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/fuzzy-pears-repair.md: [@cloudflare/wrangler]
  • packages/vite-plugin-cloudflare/src/tests/utils.spec.ts: [@cloudflare/wrangler]
  • packages/vite-plugin-cloudflare/src/utils.ts: [@cloudflare/wrangler]

@harshmathurx harshmathurx changed the title [vite-plugin] Handle cancelled request bodies [vite-plugin-cloudflare] Handle cancelled request bodies Aug 5, 2026
devin-ai-integration[bot]

This comment was marked as resolved.

@dario-piotrowicz
dario-piotrowicz requested review from dario-piotrowicz and removed request for penalosa August 7, 2026 10:24
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.

Vite plugin intermittently returns 500 when a Worker cancels an oversized request body

2 participants