Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does OkHttpClient have a max retry count

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?

like image 592
RajV Avatar asked Jun 17 '16 13:06

RajV


1 Answers

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

like image 93
Yuri Schimke Avatar answered Sep 22 '22 09:09

Yuri Schimke