0
votes

So I read this article https://www.baeldung.com/httpclient-timeout and it says that connection timeout adds to its own penalty if the underlying service's DNS that httpclient tries to connect to has multiple IPs configured to it.

So if I have a connection timeout set to 100ms and the called service DNS has 5 IPs mapped to it then, I am looking at a max connection timeout of 500ms assuming what works is the last IP.

Is there a way to have a cap on this connection timeout regardless what the underlying service topology is as being a client, I will always be agnostic to it.

1

1 Answers

0
votes

As far as I understood, you don't have a code-wise case to run in 5 or more IPs situation rather curiosity. So here my experience :

Since you're using RestTemplate which by default uses SimpleClientHttpRequestFactory. And as the definition of connection time out goes :

The connection timeout is the timeout in making the initial connection; i.e. completing the TCP connection handshake and getting connected to the requested Server.

So, as far as theory goes : Regardless of the underlying service topology, RestTemplate will try to make connection as per the connection timeout value.

And in order to figure out the almost exact timeout in your case, you must run some latency test, print the time differences which restTemplate is taking to get 200 OK.

Also, SimpleClientHttpRequestFactory internally uses HttpURLConnection which has default timeout of infinite (0/-1).

Yes, it has also been observed in rare cases, the connection keeps trying unless Thread.interrupt() explicitly being called to end.

Thus it becomes vital to describe your read-time-out and connection-time-out values and in this way you cap your connection to the limits you defined.

Hope this helps.