Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved issues were identified, and unit and E2E coverage validate the fix.
Pull request overview
Hardens RendererSynchronizationContext restoration to prevent context leakage and dispatcher bypass when execution-context flow is suppressed.
Changes:
- Reorders queue-marker completion and context restoration.
- Adds deterministic unit regression coverage.
- Adds server component E2E coverage.
File summaries
| File | Description |
|---|---|
src/Components/test/testassets/BasicTestApp/DispatchingComponent.razor |
Adds the suppressed-flow regression scenario. |
src/Components/test/E2ETest/ServerExecutionTests/ServerComponentRenderingTest.cs |
Verifies context restoration and dispatcher serialization. |
src/Components/Components/test/Rendering/RendererSynchronizationContextTest.cs |
Adds focused unit regression coverage. |
src/Components/Components/src/Rendering/RendererSynchronizationContext.cs |
Safely orders queue completion and context restoration. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
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.
Why
Fixes #69323.
When queued renderer work is submitted without a flowed
ExecutionContext, its continuation can inline onto the thread that releases the renderer queue.PostAsyncthen installs the renderer synchronization context on that caller-owned thread without an execution-context or thread-pool boundary to restore it. SubsequentCheckAccesscalls can incorrectly succeed and bypass dispatcher serialization.The triggering topology is outside normal Blazor guidance, but restoring the caller's synchronization context is inexpensive defensive hardening.
What changed
RendererSynchronizationContextis still current, preventing queued continuations from inlining onto the caller's thread.finallyblock.How to verify
. .\activate.ps1; dotnet test src\Components\Components\test\Microsoft.AspNetCore.Components.Tests.csproj --no-restore --filter "FullyQualifiedName~RendererSynchronizationContextTest" -v:q -p:UseIisNativeAssets=false. .\activate.ps1; dotnet test src\Components\test\E2ETest\Microsoft.AspNetCore.Components.E2ETests.csproj --no-restore --filter "FullyQualifiedName~ServerComponentRenderingTest.RestoresContextWhenQueuedWorkDoesNotFlowExecutionContext" -v:q -p:UseIisNativeAssets=false -p:EnforceE2ETestPrerequisites=trueInteractiveServercomponent repro reportedContext leaked: FalseandDispatcher overlapped: Falsetwice with the change.Risks / follow-ups
Completing the queue marker while the renderer context is current can add an asynchronous scheduling hop where a continuation previously inlined. This aligns the affected async/
Sendpath with the synchronous dispatcher overloads, which already complete their builders before restoring the context.No follow-up is currently required.