question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default behaviour of retryOnConnectionFailure is dangerous for POST requests

See original GitHub issue

Default 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:closed
  • Created 8 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

10reactions
ktchernovcommented, Mar 12, 2016

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.

0reactions
swankjessecommented, Apr 13, 2016

I think the nuanced fix we want is to recover from timeouts that occur during connect, but not during read.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found