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.
My setup
IHttpClientFactoryimplementation fromMicrosoft.Extensions.Httpboth version 2.1.1 & 2.2.0-preview3-35497When making a request from Angular to a server-side method that in turns makes an HTTP request using an
HttpClientobtained from theIHttpClientFactoryimplementation, the application deadlocks.It's worth mentioning that if instantiating an
HttpClientmanually, the method does not deadlock.In order to use
IHttpClientFactoryoutside 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
Loadmethod from anAngularcontroller:[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
GetDataAsynchangs, most probably deadlocking.Note that if uncommenting the line
client = new HttpClient();the method does not hang anymore.