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

Analyzer proposal: pass CancellationToken explicitly #591

Closed
sharwell opened this issue Feb 14, 2020 · 3 comments
Closed

Analyzer proposal: pass CancellationToken explicitly #591

sharwell opened this issue Feb 14, 2020 · 3 comments

Comments

@sharwell
Copy link
Member

sharwell commented Feb 14, 2020

This analyzer would report cases where a method is called with an implicit cancellation token:

async Task Method1Async() {
  await Method2(); // Diagnostic
  await Method3(); // Diagnostic
  Method4(); // Diagnostic
}

async Task Method2Async(CancellationToken cancellationToken = default) { }

async Task Method3Async() { }
async Task Method3Async(CancellationToken cancellationToken) { }

void Method4() { }
void Method4(CancellationToken cancellationToken) { }

Each of the three cases [should|should not] have the same diagnostic ID:

  1. Calling an asynchronous method using the default value for an optional CancellationToken parameter
  2. Calling an overload of an asynchronous method, where a different overload accepts a CancellationToken
  3. Calling a synchronous method that accepts a CancellationToken (as an optional parameter or a different overload)
@AArnott
Copy link
Member

AArnott commented Feb 14, 2020

See also #394 and consider how they will relate.

@gundermanc
Copy link
Member

+1 on this one. See this recent regression bug in LSP client due to failure to propagate CancellationTokens: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1083283

It has actually been fixed on at least 2 occasions before.

@Youssef1313
Copy link

This was implemented in roslyn-analyzers in dotnet/roslyn-analyzers#3641

@AArnott AArnott closed this as completed Aug 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants