10

I've set 1500 as initialTimeoutMs in DefaultRetryPolicy as below but it doesn't consider the timeout:

request.setRetryPolicy(new DefaultRetryPolicy(1500
        , DefaultRetryPolicy.DEFAULT_MAX_RETRIES
        , DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

I disconnected the WiFi on my device to test it's timeout and I saw these times in the Logcat:

2019-12-16 14:28:15.892 I/MyClass: request sent
2019-12-16 14:28:35.930 I/MyClass: request caught onError

It took more than 20 seconds while I expected to catch either onResponse or onError after 1.5 seconds!!!

Alireza Noorali
  • 3,129
  • 2
  • 33
  • 80
  • I believe that there is a retry logic after a backoff. So the request is sent, after 1.5 secs it times out and then retries after some random time. Overall the number of retires is DefaultRetryPolicy.DEFAULT_MAX_RETRIES – Abhishek Ranjan Dec 16 '19 at 11:32
  • what is your value for max_tries and backoff_multiplies ? – Karan Khurana Dec 16 '19 at 11:35
  • Both of them have default values. in DefaultRetryPolicy.java: `public static final int DEFAULT_MAX_RETRIES = 1;` `public static final float DEFAULT_BACKOFF_MULT = 1f;` – Alireza Noorali Dec 16 '19 at 12:32

2 Answers2

3

According to your configure. Your timeout should be 3 secs. Referring to http://prasadthangavel.blogspot.com/2013/12/why-volley-android-has-provided-two.html

I think you should make DEFAULT_BACKOFF_MULT zero.

littlebear333
  • 710
  • 2
  • 6
  • 14
0

Use 5 sec because 15 sec it much more for giving in timeout..

int TIME_OUT = 500; //use 5 sec it will work fine with it..

request.setRetryPolicy(new DefaultRetryPolicy(
    TIME_OUT, 
    DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
    DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));