Skip to content

Order root component operations without serializing circuit batches - #69484

Open
javiercn wants to merge 5 commits into
mainfrom
javiercn/narrow-root-component-ordering
Open

javiercn wants to merge 5 commits into
mainfrom
javiercn/narrow-root-component-ordering

Conversation

@javiercn

@javiercn javiercn commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Why

UpdateRootComponents batches can overlap when lifecycle handlers, inbound middleware, rendering, or client acknowledgments yield. A dependent batch could apply its operations before its predecessor had even invoked Add/Update/Remove. Serializing entire batches would fix that ordering but unnecessarily make later batches wait for rendering, post-next() middleware, or a slow client acknowledgment.

Fixes #59657.

What changed

  • On the renderer dispatcher, each batch captures the previous batch's operations-applied task and installs its own TaskCompletionSource with asynchronous continuations. It awaits its predecessor without blocking the dispatcher. The barrier completes immediately after Add/Update/Remove have been invoked, or after inbound middleware returns without invoking next(); it does not wait for rendering, quiescence, post-next() middleware, or acknowledgment.
  • A failure before operations are applied faults the barrier, so queued batches do not apply operations. The first failure marks the circuit errored, follows the existing log / UnhandledException / client-error flow, and causes circuit termination through CircuitRegistry. Later batches skip operations and do not report the same error again. If a batch fails after releasing its barrier, operations already started by another batch may finish; subsequent batches still see the errored state and do not start operations.
  • Preserve successful acknowledgment behavior and state-store cleanup. No lock, bounded queue, disposal cancellation, or whole-batch serialization is introduced.

Validation

  • Targeted Server build via eng/build.cmd: succeeded with zero warnings/errors.
  • dotnet test src\Components\Server\test\Microsoft.AspNetCore.Components.Server.Tests.csproj --no-build --filter 'FullyQualifiedName~CircuitHostTest|FullyQualifiedName~CircuitRegistryTest' -p:UseIisNativeAssets=false: 80 passed.
  • Before the failure-propagation fix, both lifecycle/inbound failure test rows applied a successor's root component, and a post-next() failure allowed a later batch to apply; each failed at the expected assertion and passed with the fix. A gated-acknowledgment regression likewise showed a short-circuited batch previously held its successor until acknowledgment, and passes now.

@javiercn
javiercn requested a review from a team as a code owner September 24, 2026 09:49
Copilot AI lite review requested due to automatic review settings September 24, 2026 09:49
@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label Sep 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Release the barrier immediately after the inbound pipeline returns on short circuits, and strengthen the corresponding test.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

This PR orders root-component operation batches without waiting for rendering or client acknowledgments.

Changes:

  • Adds dispatcher-confined barriers between batches.
  • Releases barriers on success and failure paths.
  • Adds sequencing coverage for middleware, dependencies, failures, and acknowledgments.
File Summary Findings
src/​Components/​Server/​test/​Circuits/​CircuitHostTest.cs Adds ordering and failure-path tests. Short-circuit ordering test does not block the acknowledgment send, so it cannot verify early barrier release.
src/​Components/​Server/​src/​Circuits/​CircuitHost.cs Implements root-component batch ordering. Inbound short circuits release the barrier only after the end-update send completes.


Assert.True(entered, "The initial circuit handler did not enter the gate.");

Browser.Click(By.Id("navigation-gate-next"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test still passes if the click does a full page reload. The gate only holds the first circuit opened after arm, so after a reload the second page gets a new, ungated circuit, becomes interactive, and the click-count assertion passes without exercising the CircuitHost barrier change.

Could we assert the navigation was enhanced (same page and circuit)? ClientValidationTest already does this with MarkEnhancedNavProbe / AssertWasEnhancedNavigation: set window.__enhancedNavProbe = true before clicking navigation-gate-next, then check it's still set once navigation-gate-second-button exists. A reload clears it.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Oct 9, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Blazor] Custom CircuitHandler latency breaks WS connection on navigation

3 participants