Skip to content

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

Open

Description

@diegoavalon

Summary

In production Cloudflare builds, createManifestLoader (dist/assets-*.mjs in 1.11.0, dist/routing-assets-*.mjs in 1.2.1) fetches /.vite/manifest.json through the ASSETS binding on the first page render in each isolate. While that fetch is in flight, the promise is stored in closure state (pending) and every concurrent page request awaits the same promise:

pending ??= (async () => {
  const response = await assets.fetch(new Request(new URL("/.vite/manifest.json", request.url).toString()));
  if (!response.ok) return null;
  cached = await response.json();
  return cached;
})().finally(() => {
  pending = null;
});
return pending;

On Workers, I/O belongs to the request that started it. If that request is canceled (client reload or disconnect) while the fetch is in flight, the fetch may never settle in the other requests' context. Then pending is never cleared and cached is never set, so every later HTML request in that isolate waits on it indefinitely. API routes are unaffected because they never build asset tags.

Cloudflare documents this class of problem: sharing promises or I/O objects across requests can cause hangs or "Cannot perform I/O on behalf of a different request" errors.

The code is unchanged in the latest release (1.11.0). The shared promise was introduced deliberately in #528 ("deduplicate concurrent client manifest loads") to speed up cold bursts; I don't think that change considered a request being canceled mid-fetch.

What we observed (void 1.2.1, @void/react 1.2.1)

  • One client, Windows Chrome, got a blank page on an SSR route on two consecutive evenings. It recovered on its own overnight.
  • Worker tail: document requests to the page ran 18–50 s wall time with 1–5 ms CPU and ended with outcome canceled. No exceptions or logs.
  • At the same time, from the same client: API routes, including authenticated JSON, and static assets including /.vite/manifest.json served normally. The page loaded fine from other networks and locations.
  • A redeploy restored the page immediately.
  • After we deployed the patch below (per-request fetch, 5 s timeout), the page has not hung again in over a week of daily use.

Honest caveat: I could not reproduce this deterministically. Local workerd / wrangler dev kept the originating subrequest alive after the client disconnected. I also have no production log that pins the stall to this await, because the hung requests logged nothing. The symptoms fit closely, and the shared cross-request promise is a hazard regardless, which is why I'm reporting it.

Suggested fix

Don't share the in-flight promise across requests; only share the parsed result. A bounded timeout also turns any future stall into a visible error:

function createManifestLoader() {
  let cached = null;
  return async (request, env) => {
    if (cached) return cached;
    const injected = globalThis.__VITE_MANIFEST__;
    if (typeof injected === "object" && injected) return (cached = injected);
    const assets = env?.ASSETS;
    if (!assets || typeof assets.fetch !== "function") return null;
    const response = await assets.fetch(new Request(new URL("/.vite/manifest.json", request.url).toString()));
    if (!response.ok) return null;
    return (cached = await response.json());
  };
}

The cost is that a few concurrent cold requests in a new isolate each fetch a small local asset once.

A more robust option would be to embed the manifest in the server bundle at build time, which is what __VITE_MANIFEST__ seems intended for. In our build it is never set, so the runtime fetch path is always taken. That removes the runtime fetch and this whole class of issue. It would also help #774, since the manifest would no longer need to be publicly served.

Environment

  • void 1.2.1, @void/react 1.2.1. Same loader code in 1.11.0.
  • Cloudflare Workers, compatibility_date 2026-02-24, nodejs_compat.
  • Assets binding with run_worker_first: ["/**"], SSR pages, Better Auth enabled.

We're running the fix above as a local patch-package patch. Because the in-flight await is the only change besides tracing, the quiet week is consistent with this being the cause, though the first deploy also recycled isolates, so it isn't proof. Happy to test a candidate fix.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions