-
Notifications
You must be signed in to change notification settings - Fork 856
Description
My setup
- ASP.NET WebForms using .NET framework 4.6.1
- Angular 1.6.6
IHttpClientFactoryimplementation fromMicrosoft.Extensions.Httpboth 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.