-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Apply CA2016: Forward CancellationToken to methods that can take it #37607
Conversation
src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs
Outdated
Show resolved
Hide resolved
...raries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs
Outdated
Show resolved
Hide resolved
...raries/System.IO.Compression.Brotli/src/System/IO/Compression/dec/BrotliStream.Decompress.cs
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/EmptyContent.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/EmptyContent.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/HttpContent.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/HttpContent.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpResponseStream.Managed.cs
Outdated
Show resolved
Hide resolved
...es/System.Threading.Channels/src/System/Threading/Channels/SingleConsumerUnboundedChannel.cs
Outdated
Show resolved
Hide resolved
...es/System.Threading.Channels/src/System/Threading/Channels/SingleConsumerUnboundedChannel.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/MultipartContent.cs
Outdated
Show resolved
Hide resolved
...libraries/Microsoft.Extensions.Hosting.Abstractions/src/HostingAbstractionsHostExtensions.cs
Outdated
Show resolved
Hide resolved
...libraries/Microsoft.Extensions.Hosting.Abstractions/src/HostingAbstractionsHostExtensions.cs
Outdated
Show resolved
Hide resolved
...libraries/Microsoft.Extensions.Hosting.Abstractions/src/HostingAbstractionsHostExtensions.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Can you also change:
runtime/eng/CodeAnalysis.ruleset
Line 117 in f40c6b6
<Rule Id="CA2016" Action="Info" /> <!-- Forward the 'CancellationToken' parameter to methods that take one --> |
to be Warning instead of Info? That will help to ensure we haven't missed any and don't miss any more moving forward.
The latest bugs in this analyzer have been merged with this PR. I merged it yesterday. |
@carlossanlop I believe you can just bump up Line 9 in 872da58
|
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/DecompressionHandler.cs
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessWaitState.Unix.cs
Show resolved
Hide resolved
src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpResponseStream.Managed.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpClient.cs
Outdated
Show resolved
Hide resolved
…erify build and test CI results
…in its default overload
...raries/System.IO.Compression.Brotli/src/System/IO/Compression/dec/BrotliStream.Decompress.cs
Show resolved
Hide resolved
Thanks for the sign-off, @jeffhandley. Can I get one more @stephentoub @mavasani @AArnott ? |
This PR applies Roslyn analyzer CA2016: It identified methods that had a
CancellationToken
parameter, and then looked inside its method body for any method invocations that could accept a token as an argument, but weren't taking it yet.The Roslyn analyzer/fixer is up for review here: dotnet/roslyn-analyzers#3641
Original issue here: #33774
@mavasani there were a couple of cases were the rule behaved strange:
A) In
MockConnection.cs
, theReadAsync
method is located in an extension class. The rule wasn't supposed to look for extension method overloads, but it did anyway, and offered a fix. Applying the fix causes the object to be substituted with the extension class, and the code now does not compile. Here's the unit test that verifies we don't offer a diagnostic when the overload is in an extension class, and it is passing. Do you know what's causing this unexpected diagnostic to be triggered?B) In
HttpContentJsonExtensions.cs
, the rule triggered a diagnostic and offered a fix, but applying it would cause a build break because the method overload that takes a token is not available in the same .NET Standard version, so I decided to wrap those invocations with a pragma directive to prevent getting the rule triggered. If this is something I can detect on the analyzer side, let me know.