Skip to content

HttpClient from HttpClientFactory deadlocks in [WebMethod] called from Angular #563

@marcpaulv

Description

@marcpaulv

My setup

  • ASP.NET WebForms using .NET framework 4.6.1
  • Angular 1.6.6
  • IHttpClientFactory implementation from Microsoft.Extensions.Http both version 2.1.1 & 2.2.0-preview3-35497

When making a request from Angular to a server-side method that in turns makes an HTTP request using an HttpClient obtained from the IHttpClientFactory implementation, the application deadlocks.
It's worth mentioning that if instantiating an HttpClient manually, the method does not deadlock.

In order to use IHttpClientFactory outside a netcoreapp2.0 project, I've used the following code:

IServiceCollection services = new ServiceCollection();
services.AddHttpClient();
ServiceProvider serviceProvider = services.BuildServiceProvider();
IHttpClientFactory _factory = serviceProvider.GetService<IHttpClientFactory>();

To Reproduce

Steps to reproduce the behavior:
Call the Load method from an Angular controller:

[WebMethod]
public static async Task> Load()
{
var data = await GetDataAsync().ConfigureAwait(false);

}
private static async Task<HttpResponseMessage> GetDataAsync()
{
HttpClient client = _factory.CreateClient();
// client = new HttpClient();
return await client.GetAsync("http://www.google.com").ConfigureAwait(false);
}

Expected behavior

The method GetDataAsync() returns.

Actual Behavior

The method GetDataAsync hangs, most probably deadlocking.
Note that if uncommenting the line client = new HttpClient(); the method does not hang anymore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions