Skip to content

[Review agent] Calibrate Blazor DI scope teardown IJSObjectReference disposal findings (#69970, #70340) #70360

Open

Description

@PureWeen

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

Across two Microsoft.AspNetCore.Components.Platform PRs (#69970 and #70340), review passes produced P2 lifecycle findings around IJSObjectReference disposal during Blazor DI scope teardown (IInternalAsyncDisposal.InternalDisposeAsync) without establishing a reachable production trigger or accounting for existing repository conventions:

  1. Non-waiting pending acquisition at DI scope disposal (#69970 Screen.cs:103 and #70340 Window.cs:88):

    • In Screen.cs (Add Screen to Microsoft.AspNetCore.Components.Platform #69970) and Window.cs (Add event listeners to Microsoft.AspNetCore.Components.Platform #70340), GetReferenceAsync() caches _jsRuntime.GetValueAsync<IJSObjectReference>(...).AsTask(), and InternalDisposeAsync() intentionally only disposes _referenceTask.Result when _referenceTask is { IsCompletedSuccessfully: true } with the comment:
      // Don't wait for a pending acquisition. It could hold up scope disposal until the JS interop timeout.
      if (_referenceTask is { IsCompletedSuccessfully: true } referenceTask)
      {
          await referenceTask.Result.DisposeAsync().ConfigureAwait(false);
      }
    • Review arms (a review model and a review model on Add Screen to Microsoft.AspNetCore.Components.Platform #69970; a review model on Add event listeners to Microsoft.AspNetCore.Components.Platform #70340) flagged a P2 leak if the scope is disposed while GetReferenceAsync() is still in flight and the JS reference arrives afterward.
    • While the source-level mechanism is conditionally possible if an IJSRuntime completes GetValueAsync after InternalDisposeAsync checks _referenceTask.IsCompletedSuccessfully (and JSCallbackFactory.ImportModuleAsync in Add event listeners to Microsoft.AspNetCore.Components.Platform #70340 explicitly disposes a late-arriving module to satisfy BrowserJSRuntime unit tests that call ServiceProvider.DisposeAsync() while holding "import"), this exact non-waiting pattern is already established in Storage.cs:111-115 and CookieStore.cs:179-183 on main.
    • Furthermore, Window.AddEventListenerAsync already throws ObjectDisposedException after await GetReferenceAsync() (Window.cs:70), and as the author explained in #69970 comment 4489650667, Blazor DI scope disposal in supported hosts runs during Interactive Server circuit teardown (where inbound interop completion and disposal are serialized on the circuit/renderer dispatcher) or WebAssembly page unload — so a P2 production leak claim is not established without a concrete supported-host trigger.
  2. Exception propagation during IJSObjectReference.DisposeAsync at DI scope disposal (#70340 Window.cs:159, CCR comment 4489112121):

    • Separately from the pending-acquisition pattern above, CCR comment 4489112121 (and corroborating review notes) claimed that await referenceTask.Result.DisposeAsync() in Window.InternalDisposeAsync() could throw JSDisconnectedException or TaskCanceledException during circuit teardown and skip subsequent feature cleanup.
    • As the author noted in #70340 comment 4489969683, CircuitHost.DisposeAsync calls JSRuntime.MarkPermanentlyDisconnected() before disposing the DI scope (preventing new outbound calls from being sent), and JSObjectReference.DisposeAsync already suppresses JSDisconnectedException (since Suppress JSDisconnectedException in IJSObjectReference.DisposeAsync #64773).

Describe the solution you'd like

  1. Calibrate Blazor Components / JSInterop review guidance (docs/BlazorComponentsGuidance.md and/or .github/agents/review-candidate-verifier.agent.md):
    • Document the Blazor DI scope teardown contract for scoped JS interop projections (Window, Screen, Storage, CookieStore):
      • In Interactive Server, CircuitHost marks JSRuntime permanently disconnected before scope disposal runs, inbound completions are coordinated through the circuit/renderer dispatcher, and JSObjectReference.DisposeAsync already ignores JSDisconnectedException.
      • In WebAssembly, the DI scope for browser platform services lives until page unload.
      • Non-waiting disposal of a lazy Task<IJSObjectReference> (if (_referenceTask is { IsCompletedSuccessfully: true })) that matches existing Storage/CookieStore conventions is intentional so scope disposal cannot hang on a pending JS interop call, and should not be elevated as a P2 blocking production leak unless a reachable non-teardown disposal path is established in the PR.
  2. Require review-candidate-verifier to check existing sibling conventions and JSObjectReference.DisposeAsync exception contracts:
    • Before keeping a P2 disposal-leak or JSDisconnectedException propagation candidate on an IJSObjectReference, verify whether JSObjectReference.DisposeAsync already suppresses the claimed exception and whether the disposal path is reachable in a supported host outside circuit/page teardown.

Additional context

Activity

  1. added theissue type on Nov 6, 2026
  2. added
    area-infrastructureIncludes: MSBuild projects/targets, build scripts, CI, Installers and shared framework
    on Nov 6, 2026
  3. github-actions commented on Nov 6, 2026

    @github-actions
    Contributor

    Triage Summary

    Area: area-blazor (Blazor DI scope teardown, IJSObjectReference, Microsoft.AspNetCore.Components.Platform)
    Type: Task (preserved)

    Potential Duplicates

    • None found

    Notes

    Generated by Issue Triage Agent for dotnet/aspnetcore for #70360 · copilot · auto · 21.5 AIC · ⌖ 1.08 AIC · ⊞ 7.7K · ◷

  4. added this to the Backlog milestone on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Componentsarea-infrastructureIncludes: MSBuild projects/targets, build scripts, CI, Installers and shared framework

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions