I am setting the retry on connection failure option for OkHttpClient.
client = new OkHttpClient();
client.setRetryOnConnectionFailure(true);
I will like to know how many times it will keep trying. Looking at the source code I did not see any maximum limit. How do I configure the client to stop trying after a few attempts?
There are more docs here https://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.Builder.html#retryOnConnectionFailure-boolean-
Configure this client to retry or not when a connectivity problem is encountered. By default, this client silently recovers from the following problems:
- Unreachable IP addresses. If the URL's host has multiple IP addresses, failure to reach any individual IP address doesn't fail the overall request. This can increase availability of multi-homed services.
Stale pooled connections. The ConnectionPool reuses sockets to decrease request latency, but these connections will occasionally time out.
Unreachable proxy servers. A ProxySelector can be used to attempt multiple proxy servers in sequence, eventually falling back to a direct connection.
Set this to false to avoid retrying requests when doing so is destructive. In this case the calling application should do its own recovery of connectivity failures.
But generally, I believe it is intended to retry when there is an existing stale connection, or alternate paths that can be retried. Not to retry exactly the same thing indefinitely.
Also see ConnectionSpecSelector.connectionFailed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With