Closed
Labels
Cost:SWork that requires one engineer up to 1 weekPriority:1Work that is critical for the release, but we could probably ship withoutapi-approvedAPI was approved in API review, it can be implementedarea-System.Threading.Taskscode-analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixer
Milestone
Description
Background and Motivation
The VSTHRD103 analyzer exists and it is broadly valuable. We should promote this analyzer to be part of the standard set of analyzers that ship with the .NET SDK.
Examples of patterns that are flagged by this analyzer
Task DoAsync()
{
file.Read(buffer, 0, 10);
}All methods where an Async-suffixed equivalent exists will produce this warning
when called from a Task-returning method.
In addition, calling Task.Wait(), Task<T>.Result or Task.GetAwaiter().GetResult()
will produce this warning.
Solution
Await the async version of the method:
async Task DoAsync()
{
await file.ReadAsync(buffer, 0, 10);
}Metadata
Metadata
Assignees
Labels
Cost:SWork that requires one engineer up to 1 weekPriority:1Work that is critical for the release, but we could probably ship withoutapi-approvedAPI was approved in API review, it can be implementedarea-System.Threading.Taskscode-analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixer
Activity
stephentoub commentedon Dec 6, 2020
This is worth pursuing in some fashion, but it also has the potential to be very noisy, e.g. it'll wreak havoc on the pattern of sharing one code path between async and sync code, e.g.
runtime/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs
Lines 1304 to 1314 in a5d0bcf
jeffhandley commentedon Dec 6, 2020
I expect one of the first steps we'll take on this proposal is to run the existing analyzer against the runtime repo. From that, we can assess what the false positive rate would be and guide the path forward.
carlossanlop commentedon Jan 14, 2021
I think this analyzer offers great value. We can always set the category to Info or even Hidden to reduce the noise.
cc @buyaa-n
carlossanlop commentedon Jan 15, 2021
Considering the VSTHRD103 analyzer already exists, we want to:
Now, since this analyzer does not live in the dotnet/roslyn-analyzers repo, I'm unsure what the process would be to enable it, if we decide to do so.
@mavasani @AArnott can you help me answer the following questions?:
6 remaining items
terrajobst commentedon Jan 26, 2021
Video
carlossanlop commentedon Feb 20, 2021
I turned it on locally for the runtime repo and I got
259 Errors10 errors in CLR. I created a draft PR so we can have an official CI output linked to this issue: #48540@terrajobst @stephentoub @buyaa-n
I think this analyzer should be enabled asInfofor dotnet/runtime repo. It would also make sense to mark it asInfoglobally.Should I bring this to API review again, or would it be ok to have it approved offline?
carlossanlop commentedon Apr 8, 2021
@terrajobst based on this comment by Stephen, can you please mark this API as approved? The analyzer will be disabled by default in the runtime repo, and the default severity will be info.
jeffhandley commentedon Jun 24, 2021
We are targeting 6.0 RC1 for this analyzer & fixer.
jeffhandley commentedon Sep 15, 2021
Closed via dotnet/roslyn-analyzers#5367