xuanzhui
xuanzhui

Reputation: 1418

Does OkHttp3 auto retry POST request by default

The concern is about a bill system.

When the client(Android or PC) use okhttp3 to send a POST or PUT request, the bill server may get the request and insert a bill record in database but will response within a really long period, so the client does not manage to receive a valid(in-time) response. The point is at this circumstance, will okhttp3 re-send the request?

This is very important because if it retries, there will be duplicated records in database without comparing the old bill records.

The reason I doubt this is that the OkHttpClient.Builder has a method called retryOnConnectionFailure, how will this affect the post request behavior? As the method name is about connection.

Also the same question about the retry behavior of HttpURLConnection.

Upvotes: 1

Views: 1150

Answers (1)

xuanzhui
xuanzhui

Reputation: 1418

Refer to this issue #2394 in github. It seems that okhttp 3.2 DOES have this retry issue. And in 3.3 version, this behavior changes to
Don't recover if we encounter a read timeout after sending the request, but do recover if we encounter a timeout building a connection.

Upvotes: 1

Related Questions