Repository navigation
[browser] Preserve reacquired JSObject proxies during finalization - #137654
Merged
pavelsavara merged 1 commit intoNov 25, 2026
Merged
Conversation
Track short and long weak references in the proxy context so a queued finalizer can distinguish a reacquired proxy from an unreachable one. Defer finalization without changing explicit disposal semantics. Cover repeated reacquisition, proxy identity, explicit disposal, and eventual cleanup with a fail-first CoreCLR browser regression theory. Resolves #137467 Co-authored-by: Copilot <[email protected]>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
This was referenced Nov 16, 2026
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
maraf
approved these changes
Nov 25, 2026
pavelsavara
deleted the
pavelsavara/browser-coreclr-jsobject-finalization
branch
November 25, 2026 13:08
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
The JSObject identity cache uses resurrection-tracking weak references. After a collection queues a proxy's finalizer, marshaling can reacquire that same proxy before finalization runs. The queued finalizer then disposes a proxy that is live again, causing ObjectDisposedException in a subsequent import.
Keep both a long and a short weak reference in a named readonly JSObjectReference struct owned by the proxy context. Reacquisition refreshes the short reference when necessary. Finalization checks that signal under the existing context lock and re-registers instead of releasing a reacquired proxy. Explicit disposal remains immediate, and the finalizer continues through DisposeImpl.
Both weak-reference objects are rooted in the cache: storing the short reference only on the finalizable proxy allows its weak handle to be reclaimed before reacquisition.
The regression theory covers repeated reacquisition, identity preservation, eventual collection and JS-handle cleanup, and explicit disposal after deferred finalization.
Validation
CoreCLR browser, Debug, Chrome 151:
Result: passed with the counts above, using a matching locally cached Chrome/ChromeDriver pair. The hot-reload property avoids the known local WasmAppHost static-web-assets tooling failure.
Mono single-threaded and multithreaded execution was not run. The deterministic regression is CoreCLR single-threaded because it relies on synchronous finalizer draining. The shared implementation retains the existing context lock for threaded builds.
Explicit analyzer/style checks were attempted but did not complete cleanly: unchanged System.Threading.Channels reference sources report IDE0073; scoped formatting also reports existing import ordering and workspace-reference-load warnings. No unrelated files were changed to suppress these diagnostics.
Cost
One additional weak-reference object and weak handle per cached proxy, plus a short-reference check on cache hits. A Windows x64 .NET 10 BenchmarkDotNet model of the cache fragment measured 2.081 ns before versus 2.716 ns after, with no allocations on hits. A separate construction measurement added 24 managed bytes (48 B to 72 B); this excludes dictionary growth and unmanaged weak-handle storage. These are isolated bookkeeping measurements, not browser end-to-end results.
Regression context
The affected identity-cache logic predates #134124. The same test, exception, and helper call were reported in #93347 in 2023. A full before/after build or bisect of #134124 was not performed, so an effect on failure frequency is not excluded.
Resolves #137467
Note
This pull request was created with assistance from GitHub Copilot.