Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpClient executes requests multiple time if request timed out

HttpClient executes request 4 times if it times out. If it does not time out then it is working fine. Is it related to HttpClient?

like image 959
Geek Avatar asked Apr 14 '14 07:04

Geek


2 Answers

I found that it is HttpClient's default behaviour to execute requests 4 times if it fails. I am not sure about other kind of failures but at least with time out.

To disable this behaviour do this :

DefaultHttpClient client = new DefaultHttpClient();
// Disable default behavior of HttpClient of retrying requests in case of failure
((AbstractHttpClient) client).setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));

Here retry count is set to 0 to disable retry.

I found solution from this blog.

like image 164
Geek Avatar answered Sep 17 '22 03:09

Geek


This resolved the issue for me. Using httpclient 4.3 and above.

HttpClientBuilder.create().disableAutomaticRetries().build();
like image 42
Kehinde Adedamola Shittu Avatar answered Sep 17 '22 03:09

Kehinde Adedamola Shittu