-
Notifications
You must be signed in to change notification settings - Fork 106
Description
Currently our standalone executable1 and our library2 entrypoints are implemented synchronously. However, further down the stack we call an asynchronous method with GetAwaiter().GetResult()
component-detection/src/Microsoft.ComponentDetection.Orchestrator/Orchestrator.cs
Line 154 in 8e8c3a4
return this.Dispatch(argumentSet, CancellationToken.None).GetAwaiter().GetResult(); |
This pattern is called 'sync over async' and can easily cause deadlocks. The problem is described well in Stephen Toub's article "Should I expose synchronous wrappers for asynchronous methods?" from 20123
We should convert both entrypoints to true asynchronous calls all the way down the stack. Asynchronous Main
methods have been a feature of C# since 7.14
Footnotes
-
https://github.com/microsoft/component-detection/blob/bf900cef6e7e5d81be3e4506f9b575435d2dd414/src/Microsoft.ComponentDetection/Program.cs#L10 ↩
-
https://github.com/microsoft/component-detection/blob/8e8c3a4557380c22bd337b7c7f0b650ea27216e8/src/Microsoft.ComponentDetection.Orchestrator/Orchestrator.cs#L30 ↩
-
https://devblogs.microsoft.com/pfxteam/should-i-expose-synchronous-wrappers-for-asynchronous-methods/ ↩
-
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-7.1/async-main ↩