Skip to content

fix: prevent stack overflow in generate_transitive_esm_init on circular dependencies#9041

Merged
shulaoda merged 1 commit into
mainfrom
04-09-fix_prevent_stack_overflow_in_generate_transitive_esm_init_on_circular_dependencies
Apr 9, 2026
Merged

fix: prevent stack overflow in generate_transitive_esm_init on circular dependencies#9041
shulaoda merged 1 commit into
mainfrom
04-09-fix_prevent_stack_overflow_in_generate_transitive_esm_init_on_circular_dependencies

Conversation

@shulaoda

@shulaoda shulaoda commented Apr 8, 2026

Copy link
Copy Markdown
Member

Summary

generate_transitive_esm_init recursively traverses module import records to find included importees for ESM init call generation. It has two branches:

  1. Importee is in the same chunk → emit init call, record in visited set
  2. Importee is NOT in the same chunk → recurse into its import records

The visited-set guard (generated_init_esm_importee_ids) only existed in branch 1. When circular dependencies exist and the involved modules are in different chunks, branch 2 recurses infinitely (A → B → A → B → ...), causing a stack overflow on the rayon worker thread.

This was exposed by #8979, which prevents merging common chunks into side-effectful entry chunks — causing more modules to land in separate chunks, making branch 2 far more likely to be hit.

The fix moves the visited-set check before the branch, so it guards both paths.

Fixes #9028

Test plan

  • Added regression test issues/9028 with circular dependencies in barrel modules under strictExecutionOrder
  • Verified the crash no longer occurs on the reproduction project
  • All existing tests pass

@netlify

netlify Bot commented Apr 8, 2026

Copy link
Copy Markdown

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit ee85fda
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/69d6c5a5da3bb00008b02e7e

@shulaoda shulaoda changed the title fix: prevent stack overflow in generate_transitive_esm_init on circular dependencies fix: prevent stack overflow in generate_transitive_esm_init on circular dependencies Apr 8, 2026
@codspeed-hq

codspeed-hq Bot commented Apr 8, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 4 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing 04-09-fix_prevent_stack_overflow_in_generate_transitive_esm_init_on_circular_dependencies (ee85fda) with main (56d4f66)2

Open in CodSpeed

Footnotes

  1. 10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (a35df14) during the generation of this report, so 56d4f66 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@pkg-pr-new

pkg-pr-new Bot commented Apr 8, 2026

Copy link
Copy Markdown

Open in StackBlitz

@rolldown/browser

npm i https://pkg.pr.new/@rolldown/browser@9041

@rolldown/debug

npm i https://pkg.pr.new/@rolldown/debug@9041

@rolldown/pluginutils

npm i https://pkg.pr.new/@rolldown/pluginutils@9041

rolldown

npm i https://pkg.pr.new/rolldown@9041

@rolldown/binding-android-arm64

npm i https://pkg.pr.new/@rolldown/binding-android-arm64@9041

@rolldown/binding-darwin-arm64

npm i https://pkg.pr.new/@rolldown/binding-darwin-arm64@9041

@rolldown/binding-darwin-x64

npm i https://pkg.pr.new/@rolldown/binding-darwin-x64@9041

@rolldown/binding-freebsd-x64

npm i https://pkg.pr.new/@rolldown/binding-freebsd-x64@9041

@rolldown/binding-linux-arm-gnueabihf

npm i https://pkg.pr.new/@rolldown/binding-linux-arm-gnueabihf@9041

@rolldown/binding-linux-arm64-gnu

npm i https://pkg.pr.new/@rolldown/binding-linux-arm64-gnu@9041

@rolldown/binding-linux-arm64-musl

npm i https://pkg.pr.new/@rolldown/binding-linux-arm64-musl@9041

@rolldown/binding-linux-ppc64-gnu

npm i https://pkg.pr.new/@rolldown/binding-linux-ppc64-gnu@9041

@rolldown/binding-linux-s390x-gnu

npm i https://pkg.pr.new/@rolldown/binding-linux-s390x-gnu@9041

@rolldown/binding-linux-x64-gnu

npm i https://pkg.pr.new/@rolldown/binding-linux-x64-gnu@9041

@rolldown/binding-linux-x64-musl

npm i https://pkg.pr.new/@rolldown/binding-linux-x64-musl@9041

@rolldown/binding-openharmony-arm64

npm i https://pkg.pr.new/@rolldown/binding-openharmony-arm64@9041

@rolldown/binding-wasm32-wasi

npm i https://pkg.pr.new/@rolldown/binding-wasm32-wasi@9041

@rolldown/binding-win32-arm64-msvc

npm i https://pkg.pr.new/@rolldown/binding-win32-arm64-msvc@9041

@rolldown/binding-win32-x64-msvc

npm i https://pkg.pr.new/@rolldown/binding-win32-x64-msvc@9041

commit: ee85fda

IWANABETHATGUY commented Apr 9, 2026

Copy link
Copy Markdown
Member

Merge activity

  • Apr 9, 1:57 AM UTC: The merge label 'graphite: merge-when-ready' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Apr 9, 1:57 AM UTC: IWANABETHATGUY added this pull request to the Graphite merge queue.

@shulaoda shulaoda merged commit 1ae1584 into main Apr 9, 2026
92 checks passed
@shulaoda shulaoda deleted the 04-09-fix_prevent_stack_overflow_in_generate_transitive_esm_init_on_circular_dependencies branch April 9, 2026 01:59
@github-actions github-actions Bot mentioned this pull request Apr 9, 2026
shulaoda added a commit that referenced this pull request Apr 9, 2026
## [1.0.0-rc.15] - 2026-04-09

### 🐛 Bug Fixes

- prevent stack overflow in `generate_transitive_esm_init` on circular dependencies (#9041) by @shulaoda

### 🚜 Refactor

- agents: rename Spec-Driven Development to Context Engineering (#9036) by @hyf0

Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
@sapphi-red sapphi-red mentioned this pull request Apr 9, 2026
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Panic]: How to track down a segmentation fault?

2 participants