Skip to content

Fix Turbopack re-export cycle deadlock - #97879

Closed
sokra wants to merge 2 commits into
canaryfrom
fleet/fix-turbopack-reexport-cycle-deadlock
Closed

Fix Turbopack re-export cycle deadlock#97879
sokra wants to merge 2 commits into
canaryfrom
fleet/fix-turbopack-reexport-cycle-deadlock

Conversation

@sokra

@sokra sokra commented Aug 25, 2026

Copy link
Copy Markdown
Member

What?

Prevents Turbopack from deadlocking while following re-exports through a facade/locals-split module in an import cycle.

The supplied async-cycle regression is promoted into the normal execution suite. A synchronous variant is included as well because the investigation established that top-level await is not required: the split re-export cycle alone can trigger the deadlock.

Why?

apply_reexport_tree_shaking follows re-exports during module resolution, which itself runs inside module analysis. After following a local export from a facade to its locals module, the previous implementation queried that locals module's side effects. In the absence of a package-level side-effects declaration, that query awaited the original module's analysis.

For a cycle such as A → B → C → A, this closed an analysis dependency cycle and left the build waiting indefinitely before generated code could run. This also blocks the export-mangling work in #97770, which makes facade/locals splitting more common.

How?

A locals module is now treated as terminal by follow_reexports. It exposes only local bindings, so there is no further re-export to follow; returning it directly preserves its evaluation and side effects while avoiding an analysis-dependent side-effect/export query during resolution.

This keeps facade/locals splitting and re-export tree shaking enabled rather than narrowing either optimization.

Verification

  • cargo test -p turbopack-tests --test execution — 262 passed, 0 failed
  • cargo fmt -- --check
  • Prettier checks for both regression fixtures

vercel-fleet-prod Bot and others added 2 commits August 25, 2026 15:07
…deadlock

Turbopack deadlocks while building the module graph for an import cycle whose
modules are split into facade + locals modules and which contains an async
module. This reproduces on canary with no configuration: a single
`export { x } from './y'` in each cycle member is enough to trigger the split
(`EcmascriptExports::split_locals_and_reexports`), and one top-level `await`
makes the cycle async.

Symptom: the build never finishes. The process sits at ~0.5% CPU with entirely
flat RSS and never spawns a Node process, so it is an await that never resolves
on the Rust side, before any generated code runs -- not a spin loop and not
unbounded graph growth. For a real project this is `next build` hanging with no
output and no error; in CI it shows up only as a job timeout.

Where it stalls, from instrumented tracing:

1. The module-graph builder blocks in `primary_chunkable_referenced_modules` on
   `module.references().await` for the entry module, i.e. inside `analyze()`.
2. Resolving `import { A } from './A'` reaches `apply_reexport_tree_shaking`
   (`turbopack/src/lib.rs`), which calls `follow_reexports(A_facade, "A")`.
3. `follow_reexports` takes exactly two steps -- facade, then `<locals>` -- and
   never completes that iteration.
4. The stall is inside the locals module's `get_exports()`, which awaits the
   original module's `analyze()`, already in flight further up the same import
   cycle. That closes a turbo-tasks await cycle.

`followReexports: false` makes it pass immediately, which pins the stall to the
`follow_reexports` path rather than to async-module handling generally. Note the
topology is deliberately close to `execution/turbopack/async-modules/cycle-2`,
whose header documents an earlier bug in `compute_async_module_info_single` for
the same shape; this is a different failure and that function is never reached.

The fixture is parked under `__hangs__/`, a path that matches neither fixture
glob in `execution.rs`, so nothing runs it automatically. `__skipped__` is not
usable for a hang: `test_skipped_fails` still executes its fixtures (under
`#[should_panic]`), so a fixture that never returns would stall the whole
`test cargo unit` job. The README explains how to arm it by moving it up one
directory; both the inert state (`running 0 tests`) and the armed state
(exit 124) were verified.

Found while enabling export mangling by default in this suite
(#97672 / #97676 / #97770). Mangling makes this far easier to hit, because it
splits every module with exports rather than only re-exporting ones, but the bug
is independent of mangling and predates that work -- hence this reproduction on
plain canary.

<!-- NEXT_JS_LLM -->

Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
Co-authored-by: Luke Sandberg <210140+lukesandberg@users.noreply.github.com>
Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Stats from current PR

✅ No significant changes detected

📊 All Metrics
📖 Metrics Glossary

Dev Server Metrics:

  • Listen = TCP port starts accepting connections
  • First Request = HTTP server returns successful response
  • Cold = Fresh build (no cache)
  • Warm = With cached build artifacts

Build Metrics:

  • Fresh = Clean build (no .next directory)
  • Cached = With existing .next directory

Change Thresholds:

  • Time: Changes < 50ms AND < 10%, OR < 2% are insignificant
  • Size: Changes < 1KB AND < 1% are insignificant
  • All other changes are flagged to catch regressions

⚡ Dev Server

Metric Canary PR Change Trend
Cold (Listen) 815ms 814ms █████
Cold (Ready in log) 819ms 818ms █▆▅▅▅
Cold (First Request) 1.323s 1.325s █▆▄▃▇
Warm (Listen) 815ms 815ms █████
Warm (Ready in log) 819ms 820ms █▇▄▅▇
Warm (First Request) 1.303s 1.321s █▇▂▄▇
📦 Dev Server (Webpack) (Legacy)

📦 Dev Server (Webpack)

Metric Canary PR Change Trend
Cold (Listen) 814ms 813ms ▁█▁▁▁
Cold (Ready in log) 806ms 802ms ▂█▁▁▁
Cold (First Request) 3.386s 3.366s ▁▇▁▁▁
Warm (Listen) 813ms 813ms ▁▇▁▁▁
Warm (Ready in log) 804ms 804ms ▁█▁▁▁
Warm (First Request) 3.356s 3.397s ▁▇▁▁▁

⚡ Production Builds

Metric Canary PR Change Trend
Fresh Build 6.119s 5.922s ▇▇▇▇▆
Cached Build 3.015s 3.079s █▆▅▂▆
📦 Production Builds (Webpack) (Legacy)

📦 Production Builds (Webpack)

Metric Canary PR Change Trend
Fresh Build 24.543s 24.944s ▂█▁▁▂
Cached Build 24.710s 24.802s ▂█▁▁▁
node_modules Size 553 MB 553 MB ▁▁▁▁▁
📦 Bundle Sizes

Bundle Sizes

⚡ Turbopack

Client

Main Bundles
Canary PR Change
017_4moyv5m34.js gzip 117 B 117 B
05jocc85-b73_.js gzip 341 B N/A -
096twxhe86hwd.js gzip 7.53 kB N/A -
0cz1d0mv5g_q7.js gzip 39.4 kB 39.4 kB
0e5lgz-xcf6ln.js gzip 273 B 273 B
0enhddgqs2dl-.js gzip 265 B 265 B
0h34mejwa_7pd.js gzip 354 B 354 B
0w853zxni3ro0.js gzip 1.36 kB N/A -
1-j27ycnrp24e.js gzip 71.5 kB N/A -
13lq2aw3_0bgw.js gzip 3.52 kB N/A -
1elt1qium-r2m.css gzip 115 B 115 B
1m5vdnlf0deiv.js gzip 411 B 411 B
1nigpy_mr0xvj.js gzip 339 B N/A -
1p0l8mn2wz5f2.js gzip 1.97 kB N/A -
1s-3t9k2_uhom.js gzip 117 B N/A -
1sqoyy39jpgkq.js gzip 121 B 121 B
1tf1phijqlx9j.js gzip 220 B 220 B
2-54v5vj7orwp.js gzip 46.8 kB N/A -
2b05_424u1zq-.js gzip 120 B N/A -
2ca40xittx95r.js gzip 8.75 kB N/A -
2hgz42b8sldyc.js gzip 5.85 kB N/A -
2j02uk1ob2zes.js gzip 155 B N/A -
2kci0vnt-49o-.js gzip 113 B 113 B
2sxgl_rcrrn_p.js gzip 399 B N/A -
2u_p__ndkooh-.js gzip 5.66 kB N/A -
2vt62i17bhbdu.js gzip 2.35 kB N/A -
342di-crrg9kq.js gzip 119 B N/A -
36hfc2_979aw2.js gzip 119 B N/A -
38wfp6jjrrdfm.js gzip 131 B 131 B
3dl1ilk37-30g.js gzip 117 B N/A -
3h0us7yy7bd_o.js gzip 13.1 kB N/A -
3kvxagoobts7h.js gzip 117 B N/A -
3p99hd9vwe6ae.js gzip 13 kB N/A -
3r0475panhk6m.js gzip 123 B N/A -
3s0i-weykgzrt.js gzip 125 B N/A -
3wijk2ywqgsv9.js gzip 2.52 kB N/A -
41kebu3wv5f4d.js gzip 65.5 kB N/A -
41u5s3oe2-erp.js gzip 2.29 kB N/A -
turbopack-0d..9ejy.js gzip 3.74 kB 3.74 kB
02zc7sqlpqxn3.js gzip N/A 119 B -
0e28eh3gbwmp0.js gzip N/A 3.51 kB -
0jwho9fkrb_t3.js gzip N/A 2.29 kB -
0longconn5mlm.js gzip N/A 123 B -
0p4l3ozbez2cz.js gzip N/A 2.35 kB -
0sbh_15ejop4o.js gzip N/A 13 kB -
0skdm-9rpid8g.js gzip N/A 117 B -
0wv-h56sz83wn.js gzip N/A 120 B -
1_to3gb2_pcj4.js gzip N/A 65.5 kB -
137xup2t69ovc.js gzip N/A 1.97 kB -
1fk10s3m1oecx.js gzip N/A 400 B -
1hfmb19p0_s-a.js gzip N/A 71.5 kB -
1mxl0dqw8ap5y.js gzip N/A 154 B -
20qhkyyj2_tla.js gzip N/A 116 B -
25lb_468wpv8t.js gzip N/A 117 B -
2imyufe18bsb7.js gzip N/A 1.36 kB -
2p4n3-8-xixh_.js gzip N/A 341 B -
2vqdfieehz5do.js gzip N/A 8.75 kB -
2x99jdcpr5n8x.js gzip N/A 7.53 kB -
2xn85ykzw2v1e.js gzip N/A 13.1 kB -
34knadd6wu9qg.js gzip N/A 119 B -
37-g1kp39exux.js gzip N/A 5.85 kB -
39jq2b6t6z6up.js gzip N/A 339 B -
3a9a9tvkag_-j.js gzip N/A 2.52 kB -
3d61tgick8g6b.js gzip N/A 46.8 kB -
3hk-fj9wj-l1s.js gzip N/A 5.66 kB -
3t121tj-h0kbm.js gzip N/A 125 B -
Total 299 kB 299 kB ⚠️ +3 B

Server

Middleware
Canary PR Change
middleware-b..fest.js gzip 1.02 kB 1.02 kB
Total 1.02 kB 1.02 kB ⚠️ +1 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 846 B 846 B
Total 846 B 846 B
Build Cache
Canary PR Change
00000001.sst gzip 14.3 MB 13 MB 🟢 1.37 MB (-10%)
00000002.sst gzip 12.6 MB 13.5 MB 🔴 +906 kB (+7%)
00000003.sst gzip 13.8 MB 13.8 MB 🟢 29.6 kB (0%)
00000004.sst gzip 14.1 MB 14.5 MB 🔴 +462 kB (+3%)
00000005.sst gzip 2.75 MB 10.1 MB 🔴 +7.35 MB (+267%)
00000006.sst gzip 10 MB 2.75 MB 🟢 7.3 MB (-73%)
00000007.sst gzip 59 B 59 B
00000008.meta gzip 89 B 89 B
00000009.meta gzip 297 kB 297 kB
00000010.meta gzip 297 kB 297 kB
00000011.meta gzip 297 kB 297 kB
00000012.sst gzip 53.2 kB 53 kB
00000013.sst gzip 1.74 MB 1.79 MB 🔴 +57.5 kB (+3%)
00000014.sst gzip 59 B 59 B
00000015.meta gzip 116 B 116 B
00000016.meta gzip 327 kB 327 kB
00000017.meta gzip 403 kB 404 kB
00000018.sst gzip 54 kB 53.8 kB
00000019.sst gzip 1.36 MB 1.37 MB 🔴 +13.6 kB (+1%)
00000020.sst gzip 59 B 59 B
00000021.meta gzip 116 B 116 B
00000022.meta gzip 327 kB 327 kB
00000023.meta gzip 372 kB 372 kB
00000024.sst gzip 54.1 kB 53.8 kB
00000025.sst gzip 1.36 MB 1.37 MB 🔴 +13.7 kB (+1%)
00000026.sst gzip 59 B 59 B
00000027.meta gzip 116 B 116 B
00000028.meta gzip 327 kB 327 kB
00000029.meta gzip 372 kB 372 kB
00000030.sst gzip 53.3 kB 53.2 kB
00000031.sst gzip 1.36 MB 1.37 MB 🔴 +13.8 kB (+1%)
00000032.sst gzip 59 B 59 B
00000033.meta gzip 116 B 116 B
00000034.meta gzip 327 kB 327 kB
00000035.meta gzip 372 kB 372 kB
00000036.sst gzip 54 kB 53.8 kB
00000037.sst gzip 1.36 MB 1.37 MB 🔴 +13.7 kB (+1%)
00000038.sst gzip 59 B 59 B
00000039.meta gzip 116 B 116 B
00000040.meta gzip 327 kB 372 kB 🔴 +45 kB (+14%)
00000041.meta gzip 372 kB 327 kB 🟢 45.1 kB (-12%)
CURRENT gzip 94 B 94 B
LOG gzip 688 B 678 B 🟢 10 B (-1%)
Total 79.5 MB 79.6 MB ⚠️ +135 kB

📦 Webpack

Client

Main Bundles
Canary PR Change
3322-HASH.js gzip 65.7 kB N/A -
4191.HASH.js gzip 169 B N/A -
9784-HASH.js gzip 5.57 kB N/A -
b1ad9f4c-HASH.js gzip 63.5 kB N/A -
framework-HASH.js gzip 59.7 kB 59.7 kB
main-app-HASH.js gzip 253 B 253 B
main-HASH.js gzip 39.8 kB 39.7 kB
webpack-HASH.js gzip 1.68 kB 1.68 kB
3577.HASH.js gzip N/A 168 B -
578-HASH.js gzip N/A 65.8 kB -
8590-HASH.js gzip N/A 5.53 kB -
a8984546-HASH.js gzip N/A 63.5 kB -
Total 236 kB 236 kB ⚠️ +106 B
Polyfills
Canary PR Change
polyfills-HASH.js gzip 39.4 kB 39.4 kB
Total 39.4 kB 39.4 kB
Pages
Canary PR Change
_app-HASH.js gzip 194 B 193 B
_error-HASH.js gzip 181 B 182 B
css-HASH.js gzip 334 B 331 B
dynamic-HASH.js gzip 1.81 kB 1.81 kB
edge-ssr-HASH.js gzip 255 B 253 B
head-HASH.js gzip 349 B 351 B
hooks-HASH.js gzip 382 B 381 B
image-HASH.js gzip 5.02 kB 5.01 kB
index-HASH.js gzip 260 B 259 B
link-HASH.js gzip 2.48 kB 2.48 kB
routerDirect..HASH.js gzip 317 B 318 B
script-HASH.js gzip 384 B 386 B
withRouter-HASH.js gzip 316 B 315 B
1afbb74e6ecf..834.css gzip 106 B 106 B
Total 12.4 kB 12.4 kB ✅ -3 B

Server

Edge SSR
Canary PR Change
edge-ssr.js gzip 128 kB 128 kB
page.js gzip 293 kB 293 kB
Total 421 kB 421 kB ✅ -399 B
Middleware
Canary PR Change
middleware-b..fest.js gzip 601 B 602 B
middleware-r..fest.js gzip 156 B 156 B
middleware.js gzip 45.7 kB 45.5 kB
edge-runtime..pack.js gzip 842 B 842 B
Total 47.3 kB 47.1 kB ✅ -262 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 698 B 699 B
Total 698 B 699 B ⚠️ +1 B
Build Cache
Canary PR Change
0.pack gzip 4.8 MB 4.79 MB 🟢 9.76 kB (0%)
index.pack gzip 124 kB 125 kB
index.pack.old gzip 123 kB 123 kB
Total 5.04 MB 5.03 MB ✅ -9.89 kB

🔄 Shared (bundler-independent)

Runtimes
Canary PR Change
app-page-exp...dev.js gzip 375 kB 375 kB
app-page-exp..prod.js gzip 206 kB 206 kB
app-page-tur...dev.js gzip 374 kB 374 kB
app-page-tur..prod.js gzip 206 kB 206 kB
app-page-tur...dev.js gzip 370 kB 370 kB
app-page-tur..prod.js gzip 204 kB 204 kB
app-page.run...dev.js gzip 371 kB 371 kB
app-page.run..prod.js gzip 204 kB 204 kB
app-route-ex...dev.js gzip 82.5 kB 82.5 kB
app-route-ex..prod.js gzip 55.6 kB 55.6 kB
app-route-tu...dev.js gzip 82.5 kB 82.5 kB
app-route-tu..prod.js gzip 55.6 kB 55.6 kB
app-route-tu...dev.js gzip 82.1 kB 82.1 kB
app-route-tu..prod.js gzip 55.4 kB 55.4 kB
app-route.ru...dev.js gzip 82.1 kB 82.1 kB
app-route.ru..prod.js gzip 55.4 kB 55.4 kB
dev-validati...dev.js gzip 134 kB 134 kB
dev-validati...dev.js gzip 134 kB 134 kB
dev-validati...dev.js gzip 132 kB 132 kB
dev-validati...dev.js gzip 132 kB 132 kB
dist_client_...dev.js gzip 324 B 324 B
dist_client_...dev.js gzip 326 B 326 B
dist_client_...dev.js gzip 318 B 318 B
dist_client_...dev.js gzip 317 B 317 B
pages-api-tu...dev.js gzip 46.2 kB 46.2 kB
pages-api-tu..prod.js gzip 34.3 kB 34.3 kB
pages-api.ru...dev.js gzip 46.2 kB 46.2 kB
pages-api.ru..prod.js gzip 34.3 kB 34.3 kB
pages-turbo....dev.js gzip 54.6 kB 54.6 kB
pages-turbo...prod.js gzip 39.7 kB 39.7 kB
pages.runtim...dev.js gzip 54.6 kB 54.6 kB
pages.runtim..prod.js gzip 39.6 kB 39.6 kB
server.runti..prod.js gzip 65.9 kB 65.9 kB
use-cache-pr...dev.js gzip 73.3 kB 73.3 kB
use-cache-pr...dev.js gzip 73.3 kB 73.3 kB
use-cache-pr...dev.js gzip 71.5 kB 71.5 kB
use-cache-pr...dev.js gzip 71.5 kB 71.5 kB
Total 4.1 MB 4.1 MB
📎 Tarball URL
https://vercel-packages.vercel.app/next/commits/2a16a1c65532328753282823100b9f11da4f4a9a/next

Commit: 2a16a1c

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: 2a16a1c

@sokra sokra closed this Aug 26, 2026
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.

1 participant