fix(fetch-cache): decode residual stacked compression on Workers - #2984
Draft
james-elicx wants to merge 2 commits into
Draft
fix(fetch-cache): decode residual stacked compression on Workers#2984james-elicx wants to merge 2 commits into
james-elicx wants to merge 2 commits into
Conversation
commit: |
Contributor
|
Contributor
Performance benchmarksCompared 0 improved · 0 regressed · 6 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
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.
Summary
Content-Encodingchain lazilyv6so older partially decoded cache entries cannot be replayedFixes #2983.
Root cause
The failing origin emits stacked content codings. Node's native fetch, which Next.js uses through
originFetch, decodes the complete chain while retaining the response headers. Workerd's automatic decoder currently handles only a singlegziporbrcoding, so a stacked response can expose residual compressed bytes toresponse.json()and to vinext's binary-safe fetch cache.The adapter keeps the generic fetch-cache implementation platform-neutral. On Cloudflare Workers it:
encodeResponseBody: "manual"transport modeAccept-Encoding: gzip, deflatewhen the caller supplied nonefetch()still resolves at headersencodeResponseBody: "manual"calls untouchedNext.js reference: https://github.com/vercel/next.js/blob/canary/packages/next/src/server/lib/patch-fetch.ts
Validation
vp check packages/vinext/src/server/cloudflare-fetch-adapter.ts packages/vinext/src/server/server-globals.ts packages/vinext/src/shims/fetch-cache.ts tests/cloudflare-fetch-adapter.test.ts tests/cloudflare-fetch-cache-integration.test.ts tests/fetch-cache.test.tsvp test run tests/cloudflare-fetch-adapter.test.ts tests/cloudflare-fetch-cache-integration.test.ts tests/fetch-cache.test.ts tests/kv-cache-handler.test.ts tests/isr-cache.test.ts tests/edge-globals.test.ts(293 passed)vp run vinext#buildAccept-Encoding: gzipboth decoded the fullgzip, gzipresponse and returned JSON successfully