1

I am using a single instance of System.Net.Http.HttpClient to send requests from a windows service to multiple RESTful API's.

I ran into a strange issue where some of the HTTP requests are timing out at more or less regular intervals. I get lots of timeout somewhere every 45 - 60 minutes.

Here is the frequency of such timeouts.

Frequency of errors

Here is how I create a HttpClient,

        ServicePointManager.DefaultConnectionLimit = 100;
        _client = new HttpClient(new HttpClientHandler
        {
          UseProxy = false,
          Proxy = null
        });
        _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

The DefaultConnectinoLimit was increased after some requests timing out. Should this be increased further or is there an optimal value that I can use ?

Is there anything else that could be causing this problem ?

Any thoughts or suggestions on this is hugely appreciated.

NOTE: I am running 100 threads and using SendAsync calls on those.

M22an
  • 1,242
  • 1
  • 18
  • 35
  • It could be bottleneck on your rest server. – jekcom Jun 14 '17 at 10:19
  • There is a number of reasons why this would happen. Most of these are outside of your control i.E. The server may have a maximum time for any given connection. Any router/firewall may have such a mechanism. – MrPaulch Jun 14 '17 at 10:21
  • try increasing timeout in ScriptManager if u have one AsyncPostBackTimeout="400" – Frost_Mourne Jun 14 '17 at 10:30
  • @jekcom, first place I looked. I was not able to find this timed out request in the REST API logs at that interval. – M22an Jun 14 '17 at 13:20
  • 1
    @Frost_Mourne, I already have a timeout associated with the HttpClient set to 30 seconds and its actually timing out at that point. From what I can see this will provide the same functionality, please correct me if I am wrong. – M22an Jun 14 '17 at 13:22
  • 1
    @MrPaulch, I am facing this problem only when running from a windows service. I have another REST API calling this REST API for similar calls and haven't faced a problem with that at any point. So, I suspect that there is something when running as a windows service that is causing this problem. – M22an Jun 14 '17 at 13:25

0 Answers0