Repository navigation
fix(api): restrict Souin HTTP cache to API responses - #718
Merged
Merged
Conversation
Souin served proxied Next.js responses from Otter and Redis with empty or truncated bodies. A truncated Turbopack runtime chunk, marked immutable for a year, was then cached by Cloudflare and broke the whole PWA (admin, book covers). Move the cache handler after the Keycloak and Next.js reverse proxies so it only handles API responses.
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.
Problem
Production is broken although CI and CD pass:
/adminstays blank and/booksnever shows the book covers.The Turbopack runtime chunk
/_next/static/chunks/turbopack-077hmtqrhcoji.jsis served truncated by Cloudflare in every encoding (gzip fails the CRC check, br is 1 byte, zstd and identity are empty). The browser reportsERR_CONTENT_DECODING_FAILED, so no client JS runs: React Admin never mounts, and covers, which load client-side throughuseOpenLibraryBook, stay onLoading.Root cause
GKE logs (namespace
prod) show the following:On 2026-11-21 at 15:26:33 UTC, Cloudflare fetched the chunk from the origin. Souin answered
hit; detail=REDISwith 2306 bytes instead of 4354. Next.js sendsCache-Control: public, max-age=31536000, immutable, so Cloudflare has kept this truncated copy since then.This is not a one-off. Since 2026-11-15, Souin cache hits on proxied Next.js responses regularly come back with an empty body and a 200 status, mostly from Otter:
/_next/static/*: every chunk, CSS and font file;/(160 occurrences),/admin(19),/login.Over the last 24h, 30 of the 160 hits outside
/_nextwere empty. Every empty hit was a PWA response; API responses were fine.Souin does not check the stored body against
Content-Length, so broken copies of these proxied responses are stored and served.Fix
Move
{$CADDY_SERVER_CACHE}after the Keycloak and Next.jsreverse_proxydirectives. Souin now only handles API responses, which is what it is used for: Hydra resources invalidated through surrogate keys. PWA assets keep being cached by Cloudflare straight from Next.js. ADR 0005 is updated accordingly.Tested locally with the FrankenPHP + Souin binary, Redis and the prod cache options from
compose.prod.yaml:/_next/static/.../(text/html)/oidc/*/books.jsonld,/(application/ld+json)hit; detail=OTTER)Required after deploy
Cloudflare will keep serving the broken chunk until it is purged. Purge
https://demo.api-platform.com/_next/static/chunks/turbopack-077hmtqrhcoji.js, or purge everything. The Redis and Otter entries become unreachable once this is deployed.