Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set ConfigureAwait(bool) on IAsyncEnumerators in await foreach loops #6652

Closed
ScottRosenberg2 opened this issue May 25, 2023 · 2 comments · Fixed by #6683
Closed

Set ConfigureAwait(bool) on IAsyncEnumerators in await foreach loops #6652

ScottRosenberg2 opened this issue May 25, 2023 · 2 comments · Fixed by #6683
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers Enhancement False_Negative No diagnostic is reported for a problematic case good first issue help wanted The issue is up-for-grabs, and can be claimed by commenting
Milestone

Comments

@ScottRosenberg2
Copy link

ScottRosenberg2 commented May 25, 2023

Describe the problem you are trying to solve

Currently CA2007 requires ConfigureAwait(bool) to be set on all instances of awaiting a task.
It does not currently catch cases where you have awaited an IAsyncEnumerator in an await foreach loop.
If you write:
await foreach (var x in someIAsyncEnumerator) { }
I'd like to see it suggest:
await foreach (var x in someIAsyncEnumerator.ConfigureAwait(someBool)) { }

Currently: It does not recognize missing ConfigureAwait on IAsyncEnumerators

Describe suggestions on how to achieve the rule

Create a rule similar to CA2007, or modify CA2007 to correctly identify await foreach IAsyncEnumerators

Additional context

Not having this rule lead to having deadlocks in our code, until manually fixed.

@mavasani
Copy link
Contributor

Create a rule similar to CA2007, or modify CA2007 to correctly identify await foreach IAsyncEnumerators

@buyaa-n @jeffhandley @stephentoub

@mavasani mavasani added this to the Unknown milestone Jun 22, 2023
@stephentoub
Copy link
Member

I think we should just update CA2007 for this. It's the same case, it's just that the underlying awaits are hidden behind code gen and so you need to lift the ConfigureAwait to be specified in a different location.

@mavasani mavasani added help wanted The issue is up-for-grabs, and can be claimed by commenting False_Negative No diagnostic is reported for a problematic case good first issue and removed Needs-Review labels Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers Enhancement False_Negative No diagnostic is reported for a problematic case good first issue help wanted The issue is up-for-grabs, and can be claimed by commenting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants