Fixed circuit disconnects caused by navigation during slow custom CircuitHandler execution - #68633
Draft
BrundhaVelusamy wants to merge 2 commits into
Draft
Fixed circuit disconnects caused by navigation during slow custom CircuitHandler execution#68633BrundhaVelusamy wants to merge 2 commits into
BrundhaVelusamy wants to merge 2 commits into
Conversation
Contributor
|
Thanks for your PR, @BrundhaVelusamy. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
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.
Bug Description
When a custom
CircuitHandlerhas latency inOnCircuitOpenedAsync/OnConnectionUpAsync(e.g.,await Task.Delay(...)), navigating to a different page before the handler completes can permanently break the circuit, surfacing to the user as"Circuit has been shut down due to error".Root cause: while the initial
UpdateRootComponentsbatch is suspended awaiting the slow handler, the renderer's dispatcher yields and a second batch — triggered by the navigation — runs concurrently. This second batch can sendUpdate/Removeoperations for SSR component IDs that the first (still in-flight) batch hasn't registered yet, and the existingWebRootComponentManager.UpdateRootComponentAsync/RemoveRootComponentthrowInvalidOperationExceptionfor unregistered IDs. That exception propagates up and firesCircuitHost.UnhandledException, tearing down the circuit even though the client is otherwise healthy.Description of code changes
WebRootComponentManager.csTryRemoveRootComponent(int ssrComponentId)— returnsfalseinstead of throwing when the component was never registered.TryUpdateOrAddRootComponentAsync(...)— falls back toAddRootComponentAsyncinstead of throwing when the component was never registered.RemoveRootComponent/UpdateRootComponentAsyncare unchanged and still used by other callers.CircuitHost.csPerformRootComponentOperationsnow callsTryRemoveRootComponent/TryUpdateOrAddRootComponentAsyncforRemove/Updateoperations instead of the throwing variants._updateRootComponentsGeneration, an integer incremented on everyUpdateRootComponentscall. If a newer batch (e.g., from navigation) completes while the current batch was blocked on circuit handlers, the stale batch acknowledges the client and returns early instead of re-rendering over the already-updated page.!cancellation.IsCancellationRequested) around the client ack andUnhandledExceptioninvocation so a transient connection drop during a slow handler doesn't tear down an otherwise-recoverable circuit.Output
Before changes
59657_BeforeFix.mp4
After changes
59657_AfterFix.mp4
Fixes #59657