Add ConfigureAwait analyzer for grain code (ORLEANS0014)
#9845
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