fix: dispose orphaned sibling handle when re-marshalling the same host object#83
Merged
Merged
Conversation
When the same host object is marshalled into the VM more than once, the first registration stores both a wrapped (proxy) handle and its unwrapped sibling. Once the VM frees the proxy, the map entry goes stale and the lazy eviction in VMMap.get dropped it without disposing the still-alive sibling, leaking a handle (and aborting the debug-sync runtime on dispose). Evict with dispose so the orphaned sibling is released.
Contributor
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
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
Marshalling the same host object into the VM more than once leaks a QuickJS handle, which aborts the debug-sync runtime on
dispose()with:Minimal repro:
One
get()is fine; the second leaks. Same forget() === get().Root cause
The first registration stores both a wrapped (proxy) handle and its unwrapped sibling in
VMMap. Once the VM frees the proxy, the host-side handle goes dead and the map entry becomes stale. The lazy eviction inVMMap.getthen dropped the entry viadelete(key)without disposing the still-alive sibling, orphaning it.(Tracked this down with the debug-sync runtime: a single host-fn return registers the global graph (~420 entries) which dispose cleanly; only the re-marshalled object's sibling leaked. The leak was confirmed via
VMMap.set/deletetracing showing the stale entry beingdeleted withdispose=undefinedthen re-set.)Fix
Evict the stale entry with
delete(key, true)so the orphaned sibling is disposed. The dead primary is skipped bydelete's own.aliveguard, so this only frees the leaked sibling.Tests
Added
src/remarshalleak.test.ts— fails (runtime abort) without the fix, passes with it. Full suite: 163 passing, typecheck + lint clean.Scope note
This fixes the handle leak (relates to the dispose-leak family in #4 / #41). It does not change reference-identity behavior across the host boundary (
get() === get()is stillfalse) — that is a separate, deeper lifetime concern;marshalByReferenceremains the supported path for guaranteed identity.