Skip to content

Fix flaky docs 404 routing test - #231

Merged
tnkuehne merged 1 commit into
mainfrom
fix-docs-routing-body
Nov 19, 2026
Merged

tnkuehne merged 1 commit into
mainfrom
fix-docs-routing-body

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Why

apps/docs/tests/routing.test.ts fails intermittently in CI with TypeError: Body is unusable: Body has already been read in the "returns a docs 404 for unknown paths under a reserved prefix" cases, including on PRs that do not touch the docs app.

The test fetched the route response, dispatched a second request, and only then read the first body. Miniflare's fetch returns a new Response that wraps the body of the original Undici Response. Nothing keeps that original alive, and Undici cancels an unread body when the original is garbage collected. If collection happens during the second dispatch, the later read fails. This is an open upstream bug: cloudflare/workers-sdk#16217. Production routing is not affected: it only occurs in the Node-side test client.

What

The 404 test now reads the route body before it dispatches the next request, as the alias test already does. A short comment explains why and links the upstream issue.

Verification

  • Reproduced the CI error deterministically by forcing garbage collection (--expose-gc) between the two dispatches in a temporary copy of the test: all four 404 cases failed with the same Body is unusable error.
  • With the new order and the same forced collection, all 27 tests passed on 3 runs.
  • pnpm exec vitest run apps/docs/tests/routing.test.ts --sequence.shuffle passed 10 out of 10 runs.
  • oxfmt --check, oxlint --type-aware --deny-warnings and the docs typecheck pass.

RetriggerView in GreptileConfidence Score: 5/5

This appears safe to merge; production routing is unchanged.

Summary

The docs routing test now reads the first response body before sending the next request, avoiding the reported garbage-collection timing issue.

  • The docs 404 test reads its route response before the next request.

No actionable issues found.

Reviews (1) · Last reviewed commit: "Read the docs route body before the next..." · Reviewed by Greptile

The 404 routing test fetched the route response, dispatched a second
request, and only then read the first body. Miniflare returns a new
Response that wraps the body of the original Undici Response. When garbage
collection reclaims the original during the second dispatch, Undici cancels
the unread body and the later read fails with "Body is unusable".

Read each route body before the next dispatch, as the alias test already
does.
@tnkuehne
tnkuehne merged commit 0f8dd19 into main Nov 19, 2026
11 checks passed
@tnkuehne
tnkuehne deleted the fix-docs-routing-body branch November 19, 2026 17:11
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