Skip to content

API can deadlock when called from synchronous code. Should be using ConfigureAwait(false). #7192

Open
@jherby2k

Description

@jherby2k

Details about Problem

The nuget v3 API uses async/await extensively, but doesn't seem to use ConfigureAwait(false) internally. This means synchronous APIs have to go out of their way to avoid deadlocks by calling your code on the threadpool, like this:

var publishedPackages = Task.Run(async () =>
{
    return await (await customRepository
            .GetResourceAsync<PackageSearchResource>(cancellationTokenSource.Token)
            .ConfigureAwait(false))
        .SearchAsync("SomePackage",
            new SearchFilter(true), 0, 100, NullLogger.Instance,
            cancellationTokenSource.Token)
        .ConfigureAwait(false);
 }).Result

It would be super cool if you could add some .ConfigureAwait(false) calls wherever await is used. I don't believe there are any drawbacks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Functionality:SDKThe NuGet client packages published to nuget.orgPriority:3Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog.Triage:Investigate

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions