You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fail pending JS interop calls when the runtime disconnects - #70632
You've included unit or integration tests for your change, where applicable.
You've included inline docs for your change, where applicable.
There's an open issue for the PR that you are making.
Description
WebViewJSRuntime.MarkAsDisconnected and RemoteJSRuntime.MarkPermanentlyDisconnected only changed their disconnected flag. Calls already in JSRuntime._pendingTasks were left pending forever when no token or timeout would complete them, pinning their continuations.
Add JSRuntime.FailPendingTasks, which removes each pending call, fails it with the supplied exception and disposes its cancellation registration. Call it from both disconnect paths with the same JSDisconnectedException message those runtimes use for new calls.
Adds FailPendingTasks_FaultsAllPendingCalls, which starts two calls without a token, fails the pending tasks and asserts both throw the same exception.
Validation
dotnet test for the JSInterop test project could not be run in this environment; CI will run the new test. The change is scoped to the pending-call dictionary and the two disconnect methods.
The reason will be displayed to describe this comment to others. Learn more.
Source-only review of frozen head d2848e007184f99e5b43bec84374283b55374da5.
Validated new findings
P3, verified: the added unit test invokes FailPendingTasks directly and would still pass if either changed Server or WebView disconnect producer stopped calling it.
P2, unresolved: the new protected internal member is absent from PublicAPI.Unshipped.txt, but the assigned frozen evidence does not establish the mandatory baseline-validation contract or rejection effect.
Existing feedback coverage: none; the frozen feedback contains only the policy-service acknowledgement and /review invocation.
Unresolved: the API-baseline validation requirement and formal API-review approval cannot be established from the assigned source and frozen metadata.
Per-guide completion:docs/CrossCuttingGuidance.md complete; docs/BlazorComponentsGuidance.md complete. Both excluded target-code/test/CI/browser execution and security assessment under the supplied source-only policies.
Uncovered areas: none among materially changed areas; both routed guides covered the JS interop, Server, WebView, API-shape, and regression-test changes.
Test boundary: source inspection only; no target code, tests, CI, browser workflows, or samples were executed.
Provenance and limitations: version-2 frozen bundle; head d2848e007184f99e5b43bec84374283b55374da5, merge base 59835e6087e90b972a905dc303523cfbb5d828ef, base tip and immutable guidance commit 18781e9d03cba0f3df9cdf7fae90f77771ca9f00. Proof is source-only and limited to tracked Git bytes; symlink, submodule, and LFS targets are inert and cannot establish target behavior.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The tests do not verify cancellation-registration cleanup or pending-call failure during actual WebView and Server teardown, leaving key disconnect behavior unprotected against regressions.
Addresses #70392 by faulting in-flight JavaScript interop calls when a WebView or Server runtime permanently disconnects, preventing calls from remaining pending indefinitely.
Changes:
Adds JSRuntime.FailPendingTasks to fault pending calls and clean up cancellation registrations.
Invokes the helper from both host disconnect paths.
Records the protected API and adds a unit test for faulting multiple pending calls.
The reason will be displayed to describe this comment to others. Learn more.
Local panel review of 9081aa69e542a04f3f90d8244a15d9f918bead4f: one new issue is raised inline. It was independently endorsed by both required double-check reviewers after one of the three review arms raised it. Existing host-hook and cancellation-cleanup feedback is not repeated.
Informational only
[UNRESOLVED] WebView caught-disconnect path: at WebViewJSRuntime.cs:50, a component that catches the disconnect and calls StateHasChanged might send an old-page render batch during replacement-page attachment. Continuation timing and native cross-document delivery/order were not established. This is separate from the uncaught-fault/fatal-notification issue raised inline.
[Verifier-discarded / unestablished] Server diagnostics: at RemoteJSRuntime.cs:230, a managed diagnostic observed a pending uncaught call reaching circuit UnhandledException during disposal. Whether that reporting is an unwanted regression lacks a binding contract; the verifier dropped this candidate. It is not a request to change Server behavior.
Routine discarded checks: missing parameter-documentation/null-guard requests did not establish a behavioral defect; the API baseline is present; late/double completion and concurrent drain candidates did not establish a failure. Formal API approval was not established by this review and is not being treated as an implementation-review blocker.
Posted for informational purposes so the author can confirm the verifier didn't discard or leave unresolved a real finding; this item does not block agent-reviewed-approved.
Untested coverage gaps: production host-hook and live-token cleanup coverage remain in the existing discussions. The caught-disconnect WebView rendering/transport scenario above remains untested. No native WebView/browser run was performed.
Validation boundary: G/S used frozen-source review; O observed managed WebView IPC emission and Server exception reporting with one failing-head/passing-reverted-file control each. Browser/native delivery and visible termination, and Server Error logging, were source-traced rather than executed.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Two tests cannot reach their intended assertions because of a deadlock and an uninitialized JS runtime, while disposal still reports aggregated disconnect failures to the replacement page.
When two components await outstanding interop calls during disposal, Renderer.Dispose combines their disconnect failures into an AggregateException. This check misses that aggregate and still sends NotifyUnhandledException through the replacement page's IPC. Also suppress aggregates containing only disconnect exceptions, preserve reporting for mixed or unrelated failures, and cover the multiple-component case.
The reason will be displayed to describe this comment to others. Learn more.
Source-only review of frozen head 9b39a1c07cd90cbdb63361d7f80984f621096d7f.
Validated new findings
P2, verified: WebViewRenderer suppresses every JSDisconnectedException, including one thrown by active application component code, bypassing the prior fatal WebView notification path.
P3, discarded: the missing <param> XML element has no established consumer-visible or tooling effect; it is surfaced inline only to preserve the review skill's candidate disposition.
Existing-feedback coverage: the WebView regression test's negative-only assertion still passes if pending calls are never failed; this is already covered by inline discussion 4623612424 and follow-up 4627683238, so it was not republished as a new finding. Deduplication is not an endorsement or resolution of that thread.
Unresolved: the source-only bundle contains no non-code process metadata establishing the architecture-review and final targeted-test-review checkpoints requested by Components guidance. No behavioral candidate depends on those checkpoints.
Per-guide completion:docs/CrossCuttingGuidance.md and docs/BlazorComponentsGuidance.md completed all applicable source checks with independent gpt-5.6-sol workers. Both excluded target-code/test/CI/browser execution and security assessment under the supplied policies.
Uncovered areas: none among the materially changed JS interop, Server, WebView, public-API, and regression-test surfaces.
Test boundary: frozen-source inspection only; no target code, tests, CI, browser workflows, or samples were executed. Changed tests were assessed for behavior ownership and false-pass risk from source.
Provenance and limitations: version-2 frozen bundle; head 9b39a1c07cd90cbdb63361d7f80984f621096d7f, merge base fa10021db581bdb7dc44e84953842ac9ccb34009, base tip and immutable guidance commit 86088a4024f07c95be38e998332b35e9817cf59d. Proof is source-only and limited to tracked Git bytes; symlink, submodule, and LFS targets are inert. Feedback posted after bundle preparation is not observable.
Addressed the new review feedback: the Circuit test initializes the RemoteJSRuntime client before starting the pending call; the WebView reattach test retains the render task and replaces the page before awaiting it; and WebViewRenderer now suppresses only disconnect failures while the runtime is actually disconnected, including aggregates made entirely of disconnect failures. Application-thrown JSDisconnectedException still goes through NotifyUnhandledException.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Disconnects can still let the old WebView renderer send batches to a replacement document and cause expected circuit teardown failures to produce warning/error logs, with both paths lacking targeted regression coverage.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Prevent old renderer batches from reaching the replacement document
When a pending lifecycle call is inside an ErrorBoundary, disconnecting can synchronously render that boundary before the old renderer is disposed, bypassing this HandleException filter. The old renderer can therefore send render batches to the replacement document before its components are attached. Return a canceled task from UpdateDisplayAsync when _jsRuntime.IsDisconnected, before queuing or sending the batch, and add reattachment coverage with the pending component inside an error boundary.
Suppress alert logs for expected disconnects during circuit disposal
During circuit disposal, faulting interop awaited by a component lifecycle method reaches RemoteRenderer.HandleException and CircuitHost.ReportUnhandledException, producing Warning and Error logs for an expected disconnect. Keep the pending task fault, but exclude expected permanent-disconnect failures from these alert-oriented logs while preserving unrelated failures. Add a lifecycle-awaiting teardown test that checks the logs; the new test only stores the pending task.
The reason will be displayed to describe this comment to others. Learn more.
Local panel review of b7bd0d088a47dfe136ec32ca469259e758712ca5: one new navigation-disconnect issue is raised inline. One of the three voting arms raised it, and both required independent double-check assessors endorsed its accuracy and non-duplication. Existing old-page rendering and generic component-lifecycle logging discussions are not repeated.
Informational only
[UNRESOLVED] WebView ErrorBoundary observation: at WebViewJSRuntime.cs:52, failing a pending lifecycle call during page replacement can reach the boundary's logger or custom error callbacks before renderer disposal. No binding contract requiring those observations to be suppressed was established. This note concerns logging/callback policy, not the already-discussed stale render-batch claim.
[UNRESOLVED] Old-page JS-invokable completion: at WebViewJSRuntime.cs:52, disconnect can release a JS-invokable method awaiting an uncancellable JS call. Its retained DotNetDispatcher continuation can then use the old runtime's unguarded EndInvokeDotNet and shared IPC sender. A replacement-document callback-ID failure remains conditional: native bridge delivery, page filtering, ordering, and ID reuse were not established. This is not a verified cross-document failure.
[Verifier-discarded / unestablished] Custom cleanup reporting: at WebViewRenderer.cs:49, the disconnected-state filter also suppresses JSDisconnectedException from a custom component's asynchronous cleanup that attempts JS after disconnection. Suppression is source-established, but no independent state/resource harm or binding requirement to report arbitrary cleanup failures was established. No behavior change is requested on this basis.
Routine discarded checks: source checks did not support late/double completion, escaped-call or registration leaks, suppression of active-page/unrelated/mixed failures, failing interop in the selected ErrorBoundary logger, or a new JSObjectReference cleanup regression. The added tests' overloads, pending producers, reflection assertions, and managed dispatcher/error-handling ordering did not establish the proposed false-pass failures. Shared-exception stack-trace harm remained speculative, and Refresh already reached its generic error path after the old timeout. Previously discussed documentation/null-guard requests are not repeated; no blanket browser/Selenium requirement was inferred for managed-owned observables.
Posted for informational purposes so the author can confirm the verifier didn't discard or leave unresolved a real finding; this item does not block agent-reviewed-approved.
Untested coverage gaps: pending NavigateTo across session termination; a renderer-tracked Server lifecycle await during teardown (the added circuit test starts its call in a constructor); WebView caught-disconnect/ErrorBoundary continuations and JS-invokable completion across replacement, including actual native delivery/order. These gaps are separate from the routine negative checks above.
Validation boundary: all three arms and both double-checks used frozen-source review only; no target build, tests, native WebView, or browser run was performed.
If the circuit is disposed while RemoteNavigationManager.PerformNavigationAsync awaits Interop.NavigateTo, this now faults that call with JSDisconnectedException. For example, an external or forceLoad: true navigation can unload the page and post _blazor/disconnect before its EndInvokeJSFromDotNet reply is processed.
The unchanged filter at RemoteNavigationManager.cs:139-143 catches only TaskCanceledException while the runtime is permanently disconnected. The new exception instead reaches the generic catch, logging Error NavigationFailed and raising UnhandledException; CircuitHost then logs Error CircuitUnhandledException. At the merge base, the pending call timed out and took the explicit Debug NavigationStoppedSessionEnded path. No second registry termination is claimed.
Please include JSDisconnectedException in that permanent-disconnect navigation filter while preserving reporting for active-circuit failures, and cover a pending NavigateTo across circuit disposal. This is distinct from the existing component-lifecycle logging discussion: the framework-owned navigation consumer already has an explicit session-ended handling path.
Thanks for the fix. This does not need new public API on JSRuntime. The derived runtimes can already fail pending calls through the public DotNetDispatcher.EndInvokeJS(JSRuntime, string), which is how Blazor Server and WebView already deliver normal JS replies in CircuitHost.cs:448 and IpcReceiver.cs:85. RemoteJSRuntime and WebViewJSRuntime can track the pending call IDs in their BeginInvokeJS overrides and complete each one as failed on disconnect. Please remove the new JSRuntime API and keep the fix inside those runtimes.
@halter73 friendly bump — mergeable and open since Nov 16. Could you review the pending JS interop cleanup when the runtime disconnects?
This branch has not been deployed
No deployments
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
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.
Description
WebViewJSRuntime.MarkAsDisconnectedandRemoteJSRuntime.MarkPermanentlyDisconnectedonly changed their disconnected flag. Calls already inJSRuntime._pendingTaskswere left pending forever when no token or timeout would complete them, pinning their continuations.Add
JSRuntime.FailPendingTasks, which removes each pending call, fails it with the supplied exception and disposes its cancellation registration. Call it from both disconnect paths with the sameJSDisconnectedExceptionmessage those runtimes use for new calls.Adds
FailPendingTasks_FaultsAllPendingCalls, which starts two calls without a token, fails the pending tasks and asserts both throw the same exception.Validation
dotnet testfor the JSInterop test project could not be run in this environment; CI will run the new test. The change is scoped to the pending-call dictionary and the two disconnect methods.Fixes #70392