'Is it appropriate to cancel and retry a HTTP request in this unavailability scenario?
General scenario:
- Suppose any given user is associated to a stateful session that is managed by my service
- each session is handled by a specific host within my service
- All http requests associated to that session must ultimately be handled by the correct host
- there exists some ownership resolution protocol allowing any given host in my service to forward a user http request to the correct session owner.
- All of the hosts exist in a common virtual network and may address eachother directly
- When a host forwards a request, the session owner must respond within X seconds. If it does not respond, the host forwarding the request will failover the session and become the new session owner (assume race conditions between different forwarding hosts attempting to failover is managed in an acceptable way)
In some number of cases, the session owner may become unresponsive and oftentimes this is due to CPU finding itself in a bad state for a period. I want to optimize my retry strategy to minimize the impact of redundant http requests on the faulty host and this basically leads to the heart of my question. If the forwarding host does not hear back from the session owner after M seconds (where M == X / K where K is an integer and K > 1), does it ever make sense to cancel the request and retry again? Or is it better to just wait for a response to the first http request?
In my mind, cancelling and retrying accomplishes nothing as I've either established a tcp connection with the target host or I have not. If I have established a tcp connection, cancelling and retrying seems like it is just causing me to send request data to the target host twice. If the session isn't established then cancelling the request and retrying doesn't really provide any optimization I'm aware of. If there is no explicit error code in those M seconds, what does retrying accomplish?
For practicality, assume I'm using .net 6 and just using a standard a very simple HttpClient
to forward requests. I think this has a more generalized answer which is non-specific to dotnet.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|