Skip to content

Analyzer to avoid possible blocking code. Cover such cases as Task.Result, Task.Wait(), Task.WaitAny(), Task.WhaitAll(), GetAwaiter()

License

Notifications You must be signed in to change notification settings

unsafePtr/BlockingAsyncAnalyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prehistory

Once we run into the deadlock issue with AzureFunction. The instance was sometimes crashing with a very strange exception. My colleague Dimitar Nikolov assumed that probably there is a deadlock issue. Then we found accessing .Result property on Task instead of awaiting it. Which leads to deadlock.

Solution

I come to a solution that probably there is an analyzer to handle such cases. Hopefully, I found one in the Microsoft's repository. Unfortunately, there were several problems. The analyzer wasn't checking if property/field/variable returns Task type and was checking only methods with async prefix declaration.

My changes in the analyzer are:

  1. Changed to work in any method type (previously worked only in async methods)
  2. Check returning type for MemberAccessExpressionSyntax to be Task
  3. Removed checking for Sleep() because Task doesn't contain this definition
  4. The .GetResult() case moved to separate analyzer. Because C# evolves and we may have different types to await.

My skills weren't enough to update and migrate code fixing.

Notes

Roslyn-analyzers repository deleted some set of analyzers which include this too. They advised to use threading analyzers from the vs-threading repository.

About

Analyzer to avoid possible blocking code. Cover such cases as Task.Result, Task.Wait(), Task.WaitAny(), Task.WhaitAll(), GetAwaiter()

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published