Repository navigation
Conversation
…dows When `runFromJS()` encounters an IO setup failure, it was calling `#deinitFromExec()` which directly frees the interpreter via `allocator.destroy(this)`. However, in the JS code path the interpreter is a GC-managed object — the GC finalizer (`deinitFromFinalizer`) will later attempt to access and free the already-freed memory, causing a use-after-free / segfault. Replace `#deinitFromExec()` with `#derefRootShellAndIOIfNeeded(true)` which properly cleans up only runtime resources (IO, shell env) and marks `cleanup_state = .runtime_cleaned`, allowing the GC finalizer to safely handle the final destruction of the interpreter object. Closes #26836 Co-Authored-By: Claude <noreply@anthropic.com>
Collaborator
Author
|
Updated 2:00 PM PT - Feb 9th, 2026
❌ Your commit
🧪 To try this PR locally: bunx bun-pr 26839That installs a local version of the PR into your bun-26839 --bun |
Contributor
WalkthroughModified error handling in Changes
Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. No actionable comments were generated in the recent review. 🎉 Comment |
Collaborator
|
This is a duplicate PR |
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.
Summary
setupIOBeforeRun()fails in the JS-managed code path (runFromJS)#deinitFromExec()which directly frees the interpreter viaallocator.destroy(this), but since the interpreter is GC-managed in this code path, the GC finalizer would later access already-freed memory causing a segfaultRoot cause
In
runFromJS()(line 1156), whensetupIOBeforeRun()returns an error, the code called#deinitFromExec()which:root_ioviaderef()root_shellviadeinitImpl()allocator.destroy(this)However, when called from
runFromJS, the interpreter is a GC-managed object. The GC finalizer (deinitFromFinalizer) would later attempt to accesscleanup_state, callroot_io.deref()androot_shell.deinitImpl()again, and callallocator.destroy(this)again — all on already-freed memory.Fix
Replace
#deinitFromExec()with#derefRootShellAndIOIfNeeded(true)which:cleanup_state = .runtime_cleanedso the GC finalizer knows not to double-freeallocator.destroy(this)— lets the GC finalizer handle thatThis is consistent with how the normal completion path (
finish()) already handles cleanup.Closes #26836
Test plan
bunshell.test.ts: 340 pass, 4 pre-existing failures in unrelated "quiet" tests)throw.test.ts: 4 pass)22650-shell-crash.test.ts: 1 pass)setupIOBeforeRun()to fail + GC to run), so it cannot be reliably reproduced in a unit test🤖 Generated with Claude Code