OKHttp3: how to retry another IP address if one is unreachable

Viewed 155

does OkHttp3 support the following case:

  • x.x.x.x myapp.com
  • y.y.y.y myapp.com

we have two IPs for one hostname, looks like OkHttpClient always retry the first IP address instead of trying another available IP address.

does retryOnConnectionFailure(true) support this? from the doc, by default it should support this?

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.

1 Answers
Related