Add ConfigureAwait analyzer for grain code (ORLEANS0014)#9845
Merged
ReubenBond merged 1 commit intodotnet:mainfrom Feb 15, 2026
Merged
Add ConfigureAwait analyzer for grain code (ORLEANS0014)#9845ReubenBond merged 1 commit intodotnet:mainfrom
ConfigureAwait analyzer for grain code (ORLEANS0014)#9845ReubenBond merged 1 commit intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new Roslyn analyzer (ORLEANS0014) that detects and warns against problematic ConfigureAwait usage in grain code. Grains must maintain their execution context to ensure proper execution within the grain's activation context. Using ConfigureAwait(false) or ConfigureAwait without the ContinueOnCapturedContext flag can cause continuations to run outside the grain's context, leading to concurrency issues.
Key changes:
- New analyzer detects
ConfigureAwait(false)andConfigureAwait(ConfigureAwaitOptions)withoutContinueOnCapturedContextin grain classes - Code fix provider automatically converts
ConfigureAwait(false)toConfigureAwait(true)or adds theContinueOnCapturedContextflag toConfigureAwaitOptions - Applies to classes implementing
IGrainorISystemTargetinterfaces
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Orleans.Analyzers/ConfigureAwaitAnalyzer.cs | New analyzer implementation that detects problematic ConfigureAwait usage in grain classes |
| src/Orleans.Analyzers/ConfigureAwaitCodeFix.cs | Code fix provider that automatically corrects ConfigureAwait issues |
| src/Orleans.Analyzers/SyntaxHelpers.cs | Adds IsGrainClass extension method for detecting grain classes |
| src/Orleans.Analyzers/Constants.cs | Adds new constants for IGrainBase, IGrain, and ISystemTarget fully qualified names |
| src/Orleans.Analyzers/Resources.resx | Adds resource strings for analyzer title, message, description, and code fix title |
| src/Orleans.Analyzers/Resources.Designer.cs | Auto-generated resource accessor properties for the new analyzer messages |
| src/Orleans.Analyzers/AnalyzerReleases.Unshipped.md | Documents the new ORLEANS0014 analyzer rule |
| test/Analyzers.Tests/ConfigureAwaitAnalyzerTest.cs | Comprehensive test suite covering analyzer and code fix behavior across various scenarios |
| src/Orleans.Streaming/PersistentStreams/PersistentStreamPullingAgent.cs | Applies the analyzer fix by adding ContinueOnCapturedContext flag |
| src/Orleans.Runtime/Placement/Repartitioning/ActivationRepartitioner.MessageSink.cs | Applies the analyzer fix by adding ContinueOnCapturedContext flag |
Files not reviewed (1)
- src/Orleans.Analyzers/Resources.Designer.cs: Language not supported
|
I love this! |
9542ba1 to
98f6243
Compare
98f6243 to
c1e7e0e
Compare
rkargMsft
pushed a commit
to rkargMsft/orleans
that referenced
this pull request
Feb 27, 2026
Add analyzer and codefix for incorrect ConfigureAwait use in grain code
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Adds a new Roslyn analyzer that warns when grain code uses
ConfigureAwait(false)orConfigureAwait(ConfigureAwaitOptions)without theContinueOnCapturedContextflag.Grains must maintain their execution context to ensure proper execution within the grain's activation context. Using
ConfigureAwait(false)orConfigureAwaitwithoutContinueOnCapturedContextcan cause the continuation to run outside the grain's context, leading to concurrency issues and loss of grain identity.To make it easier for developers to stay in the pit of success, this PR introduces a new analyzer ORLEANS0014 (Warning severity) detects problematic
ConfigureAwaitusage in grain classes.It includes a code fix that automatically:
ConfigureAwait(false)toConfigureAwait(true)ConfigureAwait(ConfigureAwaitOptions.None)toConfigureAwait(ConfigureAwaitOptions.ContinueOnCapturedContext)ContinueOnCapturedContextflag to otherConfigureAwaitOptionscombinationsThe analyzer applies to classes implementing
IGrainorISystemTarget. We could extend it toIAddressable, but I am being conservative for now sinceIGrainObserverimplementations do not strictly require this. It applies toConfigureAwaitcalls onTask,Task<T>,ValueTask,ValueTask<T>,IAsyncEnumerable<T>Microsoft Reviewers: Open in CodeFlow