Repository navigation
Fix flaky docs 404 routing test - #231
Merged
Merged
Conversation
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.
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.
Why
apps/docs/tests/routing.test.tsfails intermittently in CI withTypeError: Body is unusable: Body has already been readin 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
fetchreturns a newResponsethat wraps the body of the original UndiciResponse. 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
--expose-gc) between the two dispatches in a temporary copy of the test: all four 404 cases failed with the sameBody is unusableerror.pnpm exec vitest run apps/docs/tests/routing.test.ts --sequence.shufflepassed 10 out of 10 runs.oxfmt --check,oxlint --type-aware --deny-warningsand the docs typecheck pass.

Confidence 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.
No actionable issues found.
Reviews (1) · Last reviewed commit: "Read the docs route body before the next..." · Reviewed by Greptile