Search code examples
c#asp.net-coredotnet-httpclient

HttpClient keep alive past forced idle timeout


I have API A calling API B.

API B takes a lot of time to complete (5+mn)

During that time, there are no traffic between the twos.

Between them, I have a F5 appliance with a 300s idle timeout. Not configurable for security reasons.

While API B will continue its work, I can not get the results since the connection was ended by the F5.

If I use the same HttpClient instance used to call API B to send OPTIONS or get something from API B every X seconds / make noise on the connection, will it maintain the connection past the 300s ?

I'm not sure how HttpClient would behave in such a case.


Solution

  • Thanks to everyone for their contributions.

    Sending stuff to maintain the connection would not work as any new HttpClient would create another TCP connection. The hassle to create code to ping the exact connection was not worth any effort.

    Using a message queue was feasible but I found querying the status of B too much for 1 task.

    I ended up using Hangfire :

    • Api A --> Api B --> Hangfire Job Id
    • Timer in Api A querying Hangfire Job Status in Api B. An event / exception is risen in Api A accordingly.

    (Not worth implementing SignalR in my use-case.)