Skip to content

fix(routing): stop sharing manifest fetches across requests - #904

Open
0froq wants to merge 2 commits into
voidzero-dev:mainfrom
0froq:fix/manifest-loader-cross-request
Open

0froq wants to merge 2 commits into
voidzero-dev:mainfrom
0froq:fix/manifest-loader-cross-request

Conversation

@0froq

@0froq 0froq commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

This description was drafted by an agent from the diff and the commands it ran. froQ has reviewed it.

Fixes #902

Description

createManifestLoader memoized the in-flight ASSETS.fetch for /.vite/manifest.json in a module-scope promise, so every page render in an isolate awaited the same fetch. Workers scope I/O to the request that starts it, and a canceled request can leave that fetch unsettled. The promise then never resolved, cached was never set, and every later HTML request in that isolate waited on it forever.

The loader now caches the parsed manifest and fetches it per request until one succeeds. createAssetCachePolicy held the same kind of promise for the file set it derives from the manifest, and the generated not-found handlers build that policy once per isolate, so a stall there also stopped static assets from being served. It stores the resolved set now. Cold bursts in a fresh isolate read a small local asset a few extra times, which is the cost of not sharing request-bound I/O.

Test

Both new cases use an asset binding whose first call never settles, mirroring a canceled request, then assert that a later request still resolves. keeps a stalled manifest fetch from blocking later requests covers the loader, keeps a stalled manifest lookup from blocking later asset requests covers the cache policy. The two rewritten cases pin the new semantics: the parsed manifest is cached and returned by identity, and a missing or failed fetch still retries on the next request.

Against the base branch, the stalled cases time out:

$ vp test run packages/void/test/unit/routing-runtime.test.ts -t 'stalled manifest'
     × keeps a stalled manifest lookup from blocking later asset requests 5006ms
     × keeps a stalled manifest fetch from blocking later requests 5002ms
Error: Test timed out in 5000ms.
 Test Files  1 failed (1)
      Tests  2 failed | 171 skipped (173)

With the fix:

 Test Files  1 passed (1)
      Tests  2 passed | 171 skipped (173)

A canceled request can leave its in-flight ASSETS.fetch unsettled, so the
memoized promise in the manifest loader never resolved and every later HTML
request in that isolate waited on it forever. Cache the parsed manifest
instead, and read it per request until it resolves. createAssetCachePolicy
held the same kind of promise, so it now stores the resolved file set.
@cpojer

cpojer commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

When two cold requests overlap, the first can load the manifest and the second can overwrite the cached file set with an empty set after a 404 rejection, losing cache-control: immutable for some assets. Can you look into this?

This branch has not been deployed

No deployments
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.

createManifestLoader shares an in-flight ASSETS.fetch promise across requests, which can hang all HTML page renders in a Cloudflare isolate

2 participants