Duplicated POST -request with slow request

13,338 views
Skip to first unread message

Pasi Mella-Aho

unread,
May 26, 2014, 4:16:05 AM5/26/14
to volley...@googlegroups.com
Hello,

I came a across with a problem that when using Volley the POST request is re-send even though I configured RetryPolicy to not to do so e.g.

private RetryPolicy mRetryPolicy = new DefaultRetryPolicy(
    MY_REQUEST_TIMEOUT_MS,
    0,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT); 


Then I noticed that the problem does not occur when I'm using HttpURLConnection directly.
I found out that for some mystical reason modifying HurlStack.openConnection() by adding the following line, the problem goes away:

connection.setChunkedStreamingMode(0);

I really don't know why this helps but I sure wish we could get the fix to Volley code so that I don't have to maintain own branch.


BR,  
      Pasi


Pasi Mella-Aho

unread,
Jun 5, 2014, 1:57:04 AM6/5/14
to volley...@googlegroups.com
Any comments on this, please?

I know it sounds like this is more of a bug in HttpURLConnection than in Volley but it's anyway pretty annoying that setting the RetryPolicy does not work in this case. 
The duplicated POST -request is being sent exactly at the same time as what has been set to initialTimeoutMs (the 1st. parameter for DefaultRetryPolicy).

Other people have experienced this problem too as it has been discussed in StackOverflow (android-volley-double-post-when-have-slow-request).

-Pasi-

Ficus Kirkpatrick

unread,
Jun 5, 2014, 12:06:56 PM6/5/14
to Pasi Mella-Aho, volley...@googlegroups.com
Not something I've had a chance to debug. Have you done any more investigation on why setChunkedStreamingMode resolves the problem?


--
You received this message because you are subscribed to the Google Groups "Volley Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to volley-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pasi Mella-Aho

unread,
Jun 6, 2014, 4:21:47 AM6/6/14
to volley...@googlegroups.com, pmel...@gmail.com
At least the documentation for HttpURLConnection sets it, see example code from Posting Content -chapter.

Brice Stacey

unread,
Aug 4, 2014, 2:42:24 PM8/4/14
to volley...@googlegroups.com, pmel...@gmail.com
I have encountered the same issue. I perform a request, which succeeds quickly (confirmed using a network proxy), however Volley only reports having a socket-timeout. Volley actually attempts the default retry policy, all of which succeed as the original but never seem to be handled by Volley.

For background: I am running Volley 1.0.6 using GsonRequest. The bug always happens and only happens on one of my endpoints (a POST). I am only just now building out my application, but I have another another POST, 2 PUTs, and 1 GET endpoints configured -- neither having issues.

I can only reproduce it on a Nexus 10 running 4.4. Other devices tested are an S3 on 4.1 and Nexus 5 on 4.4. I have tried all the other stacks including OkHttp and the problem remains. For what it's worth, I'm interacting with a node/express server.

Pasi's solution above with the HurlStack solved the problem.

Adnan A M

unread,
Sep 15, 2014, 10:45:54 AM9/15/14
to volley...@googlegroups.com
I can confirm the same issue, happens only in case of a particular POST request. I am testing it on 4.2.2 , with the API server running a nodejs/express configuration. I have no idea why this occurs as this is the only endpoint where such an error occurs, other API calls work flawlessly.

Israel P.T. da Silva

unread,
Oct 8, 2014, 3:58:18 PM10/8/14
to volley...@googlegroups.com
I'm having the same issue, but while some people solve the problem by modifying HurlStack.openConnection(), I was not able to. I need some help Volley is still sending two requests when retry policy is set to 0.

Tu Yimin

unread,
Oct 19, 2014, 9:17:29 AM10/19/14
to volley...@googlegroups.com, pmel...@gmail.com
Have the same issue here, especially when using a http proxy.

Currently I have to setup a large timeout. And setChunkedStreamingMode(0) do solves the problem.

Israel P.T. da Silva

unread,
Oct 19, 2014, 12:45:49 PM10/19/14
to volley...@googlegroups.com

I managed to solve my issue by setting the keep-alive property to false inside android. eg:

System.setProperty("http.keepAlive", "false")

I added this line of code inside the class where I import requestqueue and make the requests.

Also, check if you server has the keep-alive header.

This post helped get to the solution.

Dennis Pelluzi

unread,
Dec 16, 2014, 7:06:22 AM12/16/14
to volley...@googlegroups.com
I noticed a similar problem. When I add to volley queue a POST request, same times it is sent many times (the getBody() method of my Request class is called up to four times). These multiple post requests cause a error in my server.
A solution I found was set timeout to 0 as below:

private RetryPolicy mRetryPolicy = new DefaultRetryPolicy(
     0,
     DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT); 

So, it avoids resend the post. I could set a value other than zero, but I don't know how long the server will response. 
Does anyone have a suggestion?

David Barthelemy

unread,
Jan 5, 2015, 6:11:51 AM1/5/15
to volley...@googlegroups.com
Thanks Dennis, this fix works great and it also fix another issue I was encountering with HTTPS (javax.net.ssl.SSLException: SSL handshake aborted).

Rômulo Fernandes

unread,
Jun 10, 2015, 5:17:25 PM6/10/15
to volley...@googlegroups.com
From all the solutions posted, the only one that worked was turning off the connection timeout and retry.

DefaultRetryPolicy  retryPolicy = new DefaultRetryPolicy(0, -1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
request
.setRetryPolicy(retryPolicy);

queue.add(request);


And this has been reported more than a year ago, and still no fix.

Android is really a joke.

Joris Bolsens

unread,
Jul 9, 2015, 4:53:09 PM7/9/15
to volley...@googlegroups.com
I ran into a similar issue where for some reason POST requests where being made twice. the latest version of volley seems to have fixed this issue though.

Joris Bolsens

unread,
Jul 21, 2015, 5:29:21 PM7/21/15
to Volley Users
Sorry, it seems the newer version only partially fixed the issue, have this same issue but only on requests with a relatively large body (74kb).
Setting timeout to 0 fixed the issue for me as well.

Van Shu

unread,
Aug 1, 2015, 5:37:38 AM8/1/15
to Volley Users
I also found the same problem .anybody can tell me this bug fix or not ?

在 2015年7月22日星期三 UTC+8上午5:29:21,Joris Bolsens写道:

Joris Bolsens

unread,
Aug 3, 2015, 1:45:30 PM8/3/15
to Volley Users
yes, you can work around it by doing:

RetryPolicy mRetryPolicy = new DefaultRetryPolicy(

 
0,
 
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
 
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
request
.setRetryPolicy(mRetryPolicy);

Jiantao Yang

unread,
Jan 6, 2016, 8:17:00 AM1/6/16
to Volley Users
Thanks. it works fine. but sometimes volley got a TimeoutException and also got the sucess code 200 after few seconds. i don't understand . ^_^

Mawgif KSA

unread,
Mar 5, 2016, 7:42:57 AM3/5/16
to Volley Users
HI.. this issue Fixed ? how ? can you guide me ?

Mawgif KSA

unread,
Mar 5, 2016, 8:03:38 AM3/5/16
to Volley Users
If communication lost between volley and server . you wont get any response from server . in this case how you are going to handle?

Poorani Shanmugam

unread,
Apr 1, 2016, 5:59:49 AM4/1/16
to Volley Users
Hello,
i m using volley library to call the service, if raise multiple hit on the same service. how to avoid that? any one help me..... pls

L Ganesh v

unread,
Jun 11, 2016, 4:43:38 PM6/11/16
to Volley Users
Thanks Dennis, It really helped


On Monday, May 26, 2014 at 11:16:05 AM UTC+3, Pasi Mella-Aho wrote:

袁浩

unread,
Sep 13, 2017, 6:36:02 AM9/13/17
to Volley Users
Hi,
Have you already known the reason for this problem?

在 2014年5月26日星期一 UTC+8下午4:16:05,Pasi Mella-Aho写道:

hdevst...@gmail.com

unread,
Jan 18, 2018, 12:03:31 PM1/18/18
to Volley Users
Because of the soft ttl in volley caching the result gets delivered from the cache and at the same time it queues another network request which also will return a result. And therefore, single request but two different results.
To avoid it like said earlier try:
 
DefaultRetryPolicy  retryPolicy = new DefaultRetryPolicy(0, -1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);

OR

DefaultRetryPolicy  retryPolicy = new DefaultRetryPolicy(0, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);

request.setRetryPolicy(retryPolicy);

queue.add(request);

First param is timeout ( milli seconds)

Rudra Vasu

unread,
Jul 28, 2018, 2:05:21 AM7/28/18
to Volley Users
how to send multiple request using volley


On Monday, May 26, 2014 at 1:46:05 PM UTC+5:30, Pasi Mella-Aho wrote:
Message has been deleted

Johnny Antony . P

unread,
Mar 4, 2020, 8:53:56 AM3/4/20
to Volley Users

Did the solution with HttpURLConnection work out to solve the double request in volley
 
On Monday, May 26, 2014 at 1:46:05 PM UTC+5:30, Pasi Mella-Aho wrote:

Jeff Davidson

unread,
Mar 4, 2020, 3:21:54 PM3/4/20
to Hari Shankar S, Volley Users
You should be able to do something like:

  public static class MyHurlStack extends HurlStack {
    @Override
    protected HttpURLConnection createConnection(URL url) throws IOException {
      HttpURLConnection connection = super.createConnection(url);
      connection.setChunkedStreamingMode(0);
      return connection;
    }
  }

I'm certainly happy to consider putting something like this in Volley itself, but I think we'd need a clearer indication of what devices are impacted by the problem, why this resolves it, etc. before we enable it across the board. And if (like the original poster says) it works on a vanilla HttpURLConnection, then it seems confusing, because all Volley is doing under the covers is using HttpURLConnection with a minimal set of parameters on top.

On Wed, Mar 4, 2020 at 5:52 AM Hari Shankar S <harish.j...@gmail.com> wrote:

How can we set connection.setChunkedStreamingMode(0); in openConnection method HurlStack class?
I have tried to extend HurlStack but failed.


Could you post some demo code?  i tried all case, including change time out, change retry to 0 and System.setProperty("http.keepAlive", "false") but it still doesn't work. 




--
You received this message because you are subscribed to the Google Groups "Volley Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to volley-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages