dotnet / dotnet/diagnostics

Add analyzers for .NET Core 3.0

Open
#93 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.3k
Forks
404
Avg merge
2d 3h
Merged PRs (30d)
38

Description

These are raw meeting notes that will be cleaned up later by @shirhatti

### Useful vs-threading analyzers for async usage

VS Threading has a bunch of useful analyzers that we'd like to push into the various parts of the core SDK. Here's the summary of things we decided about each of them.

https://github.com/Microsoft/vs-threading/blob/master/doc/analyzers/index.md#diagnostic-analyzers

* VSTHRD001 - not interesting without JTF
* VSTHRD002 - analyzer very interesting everywhere. Code Fix may fail, so maybe not interesting.
* VSTHRD003 - not interesting without JTF
* VSTHRD004 - not interesting without JTF
* VSTHRD010 - interesting to UI framework, has code fix
* VSTHRD011 - interesting AFTER asynclazy is in the framework.
* VSTHRD012 - not interesting without JTF
* VSTHRD100 - interesting for Core
* VSTHRD101 - interesting for Core
* VSTHRD102 - no. too nuanced
* VSTHRD103 - interesting for Core
* VSTHRD104 - interesting for Core (2nd tier)
* VSTHRD105 - Core tier 2
* VSTHRD106 - No
* VSTHRD107 - interesting to Core
* ??? - catch returning a Task from a method within a using block, without awaiting
* VSTHRD108 - Interesting for UI
* VSTHRD109 - Yes for UI stack
* VSTHRD110 - Yes for Core
* VSTHRD111 - Yes for Core
* VSTHRD200 - Yes for Core

### Analyzers for API usage

* HttpClient usage
* Don't await Task.Run in ASP.NET Core context
* Methods you should avoid in an async context
* It'll be data driven e.g. Monitor.Enter, BlockingCollection.Add*
* Block Task.Factory.StartNew and ContinueWith
* Always create TaskCompletionSource with TaskCreationOptions.RunContinuationsAsynchronously
* Never use TaskContinuationOptions.RunContinuationsAsynchronously in tcs ctor
* Always dispose CancellationTokenSource(s)
* Always flow CancellationToken(s) to APIs that take a CancellationToken
* Prefer async using vs using in and async method if the type has IAsyncDisposable
* Prefer async/await over directly returning Task (maybe)

### ASP.NET Core

* Do not cache the access to IHttpContextAccessor.HttpContext
* Do not capture services injected into the controllers on background threads

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.