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.
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:
- Changed to work in any method type (previously worked only in async methods)
- Check returning type for
MemberAccessExpressionSyntax
to beTask
- Removed checking for
Sleep()
becauseTask
doesn't contain this definition - 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.
Roslyn-analyzers repository deleted some set of analyzers which include this too. They advised to use threading analyzers from the vs-threading repository.