Repository navigation
test: make common/gc.js onGC() honour upstream's setImmediate contract #34176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d41aa5a
test: make common/gc.js onGC() delivery independent of FinalizationRe…
cirospaciari b400607
test: restore the tls-connect-memleak musl quarantine, with the real …
cirospaciari 8b45b5a
Merge remote-tracking branch 'origin/main' into claude/fix-ongc-harne…
robobun 101b122
Merge remote-tracking branch 'origin/main' into claude/fix-ongc-harne…
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robobun what node.js do here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node's
onGC()(test/common/gc.js@ v26.3.0) is built on async_hooks:It creates an
AsyncResourceheld only by aWeakMapkeyed onobj. When V8 collectsobjtheAsyncResourcebecomes unreachable, V8 collects it, and its native finalizer callsEmitDestroy, which Node drains throughenv->SetImmediateon the next loop iteration. That's where the documented guarantee in their JSDoc comes from: "A full setImmediate() invocation passes between a global.gc() call and the listener being invoked."Bun can't use that path:
async_hooks.createHookhere only deliversinit(forTickObject) and warns thatdestroyis never called (src/js/node/async_hooks.ts:362). So there's no destroy event to hook. The WeakRef sweep after an explicitgc()is the closest mechanism that gives the same "observable by the next setImmediate" ordering, and the FinalizationRegistry stays for the two callers that never callgc()at all.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robobun check cirospaciari async hooks PR to see if it would solve this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked #31825. It wouldn't solve this on its own.
That PR's
src/js/node/async_hooks.tsdiff coversAsyncLocalStorage(run/disablerestore semantics,defaultValue,name,withScope) andAsyncResource.bind()parity, but it doesn't touchcreateHookat all. Thedestroyhook still never fires; the PR's own vendoredtest-eventemitter-asyncresource.jsadds a comment saying exactly that ("Bun does not implement createHook event [delivery]").Node's
onGC()needs two things that remain missing after #31825:createHook({ destroy })actually deliveringdestroyevents.AsyncResourcehaving a native finalizer that callsemitDestroywhen GC collects it. In Node theAsyncResourceis a nativeAsyncWrap; V8 runs its C++ destructor, which queuesEmitDestroy. In BunAsyncResourceis a plain JS class with no JSC finalizer, so nothing fires on collection even if (1) were wired up.So even with #31825 merged,
common/gc.jsstill needs a non-async_hooks mechanism, and the WeakRef sweep here is that mechanism. If/when Bun grows a native-backedAsyncResourcewith GC-drivendestroy, this file could switch to upstream's verbatim implementation and drop the WeakRef path.