Repository navigation
fix(blocks,tanstack): joiners of a cancelled owner's single-flight no longer hang - #714
Merged
Merged
Conversation
… longer hang Module-level dedup maps let request B join the flight request A started. On Workers, when A's client disconnects the runtime cancels A's I/O AND its timers — including the owner's `withInflightTimeout` — so the shared Promise never settles, its `.finally()` never frees the slot, and every later request for the same key hangs for the life of the isolate (CPU ~0, wall 100s → 524). Only a deploy (fresh isolates) cleared it in production. `cachedLoader` already handled this (`joinInflight` + `publishInflight`); the other sites did not. Same pair applied to: - cms/sectionLoaders: `sectionLoaderInflight`, `layoutInflight` - cms/resolve: `resolvedLayoutInflight` (Header/Footer — every page joins it) - sdk/fetchCache: `inflight` (upstream fetch dedup) - tanstack routes/withSiteGlobals: `resolveSiteGlobals` (had no timeout at all) Joiners are bounded by their OWN request's timer and re-run on stall; the owner's work is kept alive with `waitUntil` (`cacheBackground`); slots are released by identity so a late `finally` never evicts a newer flight. Tests simulate the cancelled owner (work never settles, owner timers swallowed) and fail without the fix.
…resolve; siteGlobals uses joinInflight Review follow-ups on the cancelled-owner fix: - New `cms/inflightCancelledOwner.test.ts`: layout section, cacheable section and the resolved Header/Footer layout (resolveDecoPage) — joiners of a flight whose owner timer died must recover on their own timer and keep their own index; plus the owner's work reaching `ctx.waitUntil`. All four fail on 7.x without the fix. - Export `@decocms/blocks/sdk/inflightTimeout` and use the real `joinInflight` in withSiteGlobals instead of an inlined copy. - withSiteGlobals releases its slot by identity from an outer `.finally` (always async), so a slow owner no longer evicts a newer flight.
…ed flight
`joinInflight` takes an optional label and emits one structured warn when a
joiner's own timer fires and it re-runs instead of waiting:
[inflight] stall {"label":"layoutSection <key>","waitedMs":10000}
Until now that event was silent, so there was no way to tell how often owners
are cancelled (client disconnects) or which key got poisoned. Every call site
passes a label (sectionLoader, layoutSection, resolvedLayout, fetchCache,
cachedLoader, dedupLoader, siteGlobals) so the volume can be grouped by kind
and key in Workers logs.
# Conflicts: # packages/blocks/src/sdk/cachedLoader.ts
…led fetch join once - sharedResolvedLayout: a joiner that stalls reads the layout cache before resolving again, since a newer flight may have filled it meanwhile. - fetchCache: a join counts as HIT only when the shared fetch answers it; after a stall the retry records its own decision, so one call isn't HIT and MISS. - Merge 7.x (cachedLoader: keep the stall label and pass ctx to the retry). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 17, 2026
|
🎉 This PR is included in version 7.86.6 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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 incident on a TanStack storefront (14/10 and 15/10, both starting 16:10 UTC): ~1.2k requests/h site-wide (
/_serverFn, pages, PDP) hung with CPU 1–3 ms and wall 100 s until Cloudflare returned 524 (outcome: canceled). Spread across all colos. Every time, a no-op redeploy cleared it instantly, so the stuck state was held by the isolate.Root cause
Module-level single-flight maps let request B join the flight request A started. On Workers, when A's client disconnects (reload, navigation, closed tab) the runtime cancels A's I/O and its timers, including the owner's
withInflightTimeout. The shared Promise never settles,.finally()never frees the slot, and every later request for the same key hangs for the life of the isolate.cachedLoaderalready documents and handles this (joinInflight+publishInflight/cacheBackground). These sites did not:blocks/src/cms/sectionLoaders.tssectionLoaderInflight,layoutInflightblocks/src/cms/resolve.tsresolvedLayoutInflight(Header/Footer: every page joins it)blocks/src/sdk/fetchCache.tsinflight(upstream fetch dedup)tanstack/src/routes/withSiteGlobals.tsinflightinresolveSiteGlobals(no timeout at all)handle_cross_request_promise_resolutiondoesn't help here: it allows resolving another request's Promise, it doesn't stop the owner's I/O from being cancelled.Fix
Same pair as
cachedLoader, at every site:joinInflight; inlined inwithSiteGlobalsbecausesdk/inflightTimeoutisn't exported). On stall, they evict the dead slot and run again.waitUntil(cacheBackground), so a client disconnect doesn't kill the Promise others are waiting on.finallynever evicts a newer flight.Tests
Every test simulates the cancelled owner: its work never settles and its timer died with it. All of them fail (hang) on
7.xwithout the fix and pass with it.cms/inflightCancelledOwner.test.tscovers:index, and the loader runs exactly twice;resolveDecoPage(sharedResolvedLayout);ctx.waitUntil.sdk/fetchCache.test.tsandroutes/withSiteGlobals.test.tseach have one cancelled-owner case.bun run test: blocks 1007/1007. tanstack 320/322; the 2 failures (workerEntry.test.ts› draft preview) fail identically on base7.x.bun run lint: 550 errors on base → 549 (pre-existing).typecheck: only pre-existingblocks-clierrors.Review follow-ups:
@decocms/blocks/sdk/inflightTimeoutis now exported, andwithSiteGlobalsuses the realjoinInflightinstead of a copy..finally, so a slow owner can't evict a newer flight.resolveSiteGlobals. It never rejected before, and a slow-but-valid resolve would turn into empty globals.Note:
wrangler devdoesn't reproduce this. Local workerd doesn't cancel the request context on client disconnect, so the owner's timer still fires.main(8.x) doesn't have these maps, so this is 7.x-only.Summary by cubic
Fixes single-flight joiners hanging when the owner request is cancelled on Workers: a client disconnect cancels that request's I/O and timers, so the shared Promise never settles and every later caller waits until the next deploy. In production this caused ~1.2k requests/h to time out at 100s (Cloudflare 524s), cleared only by a redeploy.
Applies the same pattern
cachedLoaderalready uses — joiners bounded by their own timer, the owner's work kept alive withwaitUntil(cacheBackground), and slots released by identity so a latefinallynever evicts a newer flight — to these module-level single-flight maps:blocks/src/cms/sectionLoaders.ts(sectionLoaderInflight,layoutInflight)blocks/src/cms/resolve.ts(resolvedLayoutInflight— laid out by Header/Footer, joined by every page)blocks/src/sdk/fetchCache.ts(inflightupstream fetch dedup)tanstack/src/routes/withSiteGlobals.ts(resolveSiteGlobals— had no timeout at all;sdk/inflightTimeoutis now exported so it uses the real helper)Joiners that give up now log a structured
[inflight] stallwarning labeled by call site, making cancelled-owner volume and poisoned keys visible in Workers logs.fetchCachejoin counts as HIT only when the shared fetch answers it; a stalled retry records its own MISS, so one call isn't counted twice.Tests simulate the cancelled owner (work never settles, owner timers swallowed) and hang on
7.xwithout the fix. This is7.x-only —maindoesn't have these maps.Written for commit 13c4dd2. Summary will update on new commits.