-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Add analyzer to force ConfigureAwait(false) on all awaits #31132
Comments
And like most "best practices" it's only correct like 90% of the time 😆 |
That's what pragma suppress is for. |
Or use an explicit |
Ha. Best practice is code for I don't want to explain why we want it 😋 |
@ericstj Does dotnet/runtime already have an analyzer like this? I see some references to it. If so, this might be much easier for the components moving to dotnet/runtime. |
We enable CA2007 /cc @stephentoub |
CA2007 is outdated (among other things, doesn't support ValueTask). You'll want to use the vs-threading one instead, and disable CA2007 so you aren't getting duplicate diagnostics and fixes. |
The sheer noise from vs-threading analyzers was prohibitive. If CA2007 is outdated, it should be fixed. Or if it's not being invested in because the vs-threading analyzers are being incorporated into these packages as a replacement, we'll wait for those before making any changes. At present, CA2007 is what exists for us and our customers. |
This is mostly done now. The dotnet/runtime repo already does this. We should turn on CA2007 in this repo as well though. |
@JamesNK is there anything for us to do here? Should we close this? If not, do you want to bring it for someone to pick it up in the DoI? |
I don't know what Andrew ment when he said this is mostly done. I don't think we've done anything 😬 Basically I think we should turn on CA2007 for all our libraries that can run outside of ASP.NET Core. We're writing code without We should come up with a rule to apply the analyzer setting across the repo. Perhaps all projects that are:
Note that there are some projects where the rule will be turned off. For example, the .NET SignalR client has a different strategy to avoid sync context issues (@BrennanConroy can you confirm, its been a couple of years since I looked at the .NET SignalR client code). tldr; DoI should pick this up |
I think Andrew meant we had added
Yeah, we have the weird |
I'm going to consider this resolved based on #39946. |
We don't add
ConfigureAwait(false)
to ASP.NET Core code because there is no sync context. Microsoft.Extensions.* code could execute in client apps. Not usingConfigureAwait(false)
can create deadlocks when a user mixes sync with async, e.g. dotnet/extensions#999.Consider introducing an analyzer to enforce
ConfigureAwait(false)
everywhere. A quick search of this repos source code displays many non-test awaits that don't follow best practice.I just had some good success using https://www.nuget.org/packages/ConfigureAwaitChecker.Analyzer/
The text was updated successfully, but these errors were encountered: