Default behaviour of retryOnConnectionFailure is dangerous for POST requests
See original GitHub issueDefault behaviour of OkHttpClient.Builder to set retryOnConnectionFailure
may result in POST requests being silently resent on network timeouts.
While this may be typically alright for GET requests, POST/PATCH/DELETE requests modify data, and re-submitting them without knowing whether they have been received at the other end.
Issue Analytics
- State:
- Created 8 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
Does OkHttp3 auto retry POST request by default
The reason I doubt this is that the OkHttpClient.Builder has a method called retryOnConnectionFailure , how will this affect the post request ......
Read more >retryOnConnectionFailure - OkHttp
Configure this client to retry or not when a connectivity problem is encountered. By default, this client silently recovers from the following problems:....
Read more >OkHttp is quietly retrying requests. Is your API ready? - Medium
OkHttp will potentially repeat your requests on a slow/unreliable connection “aggressively” until it succeeds. This is done for GET, POST or any other...
Read more >sttp Documentation - SoftwareMill
a default, synchronous backend, which is based on Java's HttpURLConnection ... reasonably type-safe API for making HTTP requests and reading.
Read more >VCSA 6.5 Doesnt Start after Reboot (503 Error)
Posted by chris.lubinski on Jul 2nd, 2020 at 5:56 AM ... as not being able to contact a default gateway due to bad...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have investigated this further, and there is a change in behaviour between v2 and v3 here, which is in the way SocketConnectionTimeout is handled. In v2 the request was always dropped, in v3 the connection is retried unless
retryOnConnectionFailure
is set.Compare https://github.com/square/okhttp/blob/parent-3.0.0-RC1/okhttp/src/main/java/okhttp3/internal/http/StreamAllocation.java line 336 to https://github.com/square/okhttp/blob/parent-2.7.5/okhttp/src/main/java/com/squareup/okhttp/internal/http/StreamAllocation.java line 358
This means that if the client sent a POST request, then the server received it but the response got lost due to network issues, the client will resend it again. While in v2 it would fail.
I think the nuanced fix we want is to recover from timeouts that occur during connect, but not during read.