-
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
[API Proposal]: Code analyse rule that require passing of cancellation token #82889
Comments
Tagging subscribers to this area: @dotnet/area-system-threading-tasks Issue DetailsBackground and motivationThe rule public async Task Foo(CancellationToken token)
{
await SomeMethodThatAcceptsCancellationToken(); // violation
}
public async Task Bar()
{
await SomeMethodThatAcceptsCancellationToken(); // no violation
} This can be hard to identify that the cancellation token is not forwarded down the stack as it should have been since the second method does not accept a token as a input parameter. There should be a even more strict rule that requires the forwarding of the cancellation token or to use public async Task Bar()
{
await SomeMethodThatAcceptsCancellationToken(CancellationToken.None);
} This will make it easier to maintain the code and also perform code reviews on the use of cancellation tokens if the code base. API Proposalpublic async Task Bar()
{
await SomeMethodThatAcceptsCancellationToken(); // CA20XX violation
} API Usagepublic async Task Bar()
{
await SomeMethodThatAcceptsCancellationToken(); // CA20XX violation
} Alternative DesignsNo response RisksNo response
|
Thanks. This is largely a duplicate of #78397, which proposes a rule that async methods should accept a token. I'm less inclined to have a rule about calls that aren't passed a token and don't have one to pass, as that's really just a stylistic choice as to whether to use the implicit default token or the explicit default token with None. |
duplicate of #78397 |
Background and motivation
The rule
CA2016
checks that any in scope cancellation token must be forwarded, but if the current method does not have a cancellation token there rule does result in a violationThis can be hard to identify that the cancellation token is not forwarded down the stack as it should have been since the second method does not accept a token as a input parameter. There should be a even more strict rule that requires the forwarding of the cancellation token or to use
CancellationToken.None
if the cancellation token is not need / available.This will make it easier to maintain the code and also perform code reviews on the use of cancellation tokens if the code base.
API Proposal
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: