We have been experiencing high CPU on .Net Core when calling an external service.The issue seems to be with the new JsonHttpClient. As a result, consecutive calls to the service start eating CPU and do nt release them back, resulting in 100% CPU eventually.Maybe we are doing something wrong, so please advise.

We have taken the code for JsonHttpClient from Github and investigated the issue. We see the call to

public HttpClient GetHttpClient()

nicely looks for an existing HttpClient, which is good (the link is provided with additional info)

Now, when I use the JsonHttpClient, I often hit this line:

var client = new HttpClient(handler) { BaseAddress = baseUri };

This is due to the fact that the HttpClient used is an instance variable:

public HttpClient HttpClient { get; set; }

We modified this to:

public static HttpClient HttpClient { get; set; }

And PRESTO! No more CPU consumption.

This makes me wonder: should the JsonHttpClient be used as a singleton?