Skip to content

Make Component Detection entrypoints asynchronous #221

@JamieMagee

Description

@JamieMagee

Currently our standalone executable1 and our library2 entrypoints are implemented synchronously. However, further down the stack we call an asynchronous method with GetAwaiter().GetResult()

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

  1. https://github.com/microsoft/component-detection/blob/bf900cef6e7e5d81be3e4506f9b575435d2dd414/src/Microsoft.ComponentDetection/Program.cs#L10

  2. https://github.com/microsoft/component-detection/blob/8e8c3a4557380c22bd337b7c7f0b650ea27216e8/src/Microsoft.ComponentDetection.Orchestrator/Orchestrator.cs#L30

  3. https://devblogs.microsoft.com/pfxteam/should-i-expose-synchronous-wrappers-for-asynchronous-methods/

  4. https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-7.1/async-main

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changeBreaking change, requires major version bumpstatus:in-progressSomeone is working on implementationtype:refactorRefactoring or improving of existing code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions