In one of my application, I am sending request to server using volley
provided by Google.
Problem : Timeout and error object is null on onErrorResponse(VolleyError error)
What i have tried so far :
1) First I got null error object so solved it by using below code :
@Override
protected void deliverResponse(String response) {
super.deliverResponse(response);
}
@Override
public void deliverError(VolleyError error) {
super.deliverError(error);
DebugLog.e("deliverResponse", "getNetworkTimeMs : " + error.getNetworkTimeMs());
}
So far I have got that there is timeout
happening when I got error object null
.
2) Now Application is for Android
and iOS
and web
but timeout
happens only for Android
.
Volley log for requests :
BasicNetwork.logSlowRequests: HTTP response for request
Edited Note :
Web services develoed at server end is same for all three instances (Android , Web and iOS).
Timeout
happens when too many users makes requests to the server.I have set time out to 2 minutes though volley throws timeout in 30 seconds only sometimes.
I have many answers to change server but as it is not possible so any other solution please.
I also like to add that if i can get more information about when timeout can be possible in volley ?
References I have been gone through :
httpclient-often-times-out-using-wifi-is-going-fine-with-3g
long_xmlhttprequest_ajax_requests_timeout_on_android
Edited :
I have also set retry policy as below:
request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 48,
0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
And also i do not want to retry if connection timeout.
How can i make efficient service call that can solve problem for timeout
.
Any help will be appriciated.
Thanks.
As i have tried to get solution of this issue for about two months, I did not get any perfect solution. Though I analyze some facts as below :
HttpURLConnection
but still getting same issue over there.So I think this issue is not specific from volley, but you getting this issue then i would suggest to increase server performance with customizing below
RetryPolicy
:Hope it will help.
Suggestions are always welcome :)
Please comment below if you found more proper solution.
Thanks.!
request.setRetryPolicy(new DefaultRetryPolicy( 50000, 5, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT))
set timeout time.
Try not using the require statement to connect to your database when sending request to a PHP file using volley. I've noticed a time-out only when I use something like (require "init.php") But when I directly put my DB connection information in the same file everything seems to work just fine.
IMHO, you can refer to the following:
Inside
BasicNetwork.java
, you will find some information such as:So, if your project uses Google's volley as a module (not JAR file), you can update
BasicNetwork.java
, increasingSLOW_REQUEST_THRESHOLD_MS
value, perhaps 10000 (ms) or more, for example.Another option, according to @neuron's answer at the following question:
I think you can try increase the value of NETWORK_THREAD_POOL_SIZE by using the following constructor in your app:
P/S: if you only want the lines
BasicNetwork.logSlowRequests: HTTP response for request
not displayed anymore without increasing NETWORK_THREAD_POOL_SIZE, only need to comment (//
) the linelogSlowRequests...
above (when your app uses Google's volley as a module - not jar file, notcompile mcxiaoke...
inbuild.gradle
file)Hope it helps!