title: Android Volley makes 2 requests to the server when retry policy is set to 0
body: <p>I'm working on an Android project that uses Volley for async requests and imagecaching. Somehow   a request is hitting the server twice even when I have the retry policy set to 0. I tried overriding the values from the DefaultRetryPolicy object with no success. Here's some sample code:</p>
  
  <p>The request:</p>
  
  <pre><code>@Override
  public void gravarVendaMobile(final Usuario usuarioAutenticado, final AsyncCallback&lt;String&gt; callback) {
      obterParametrosDeInicializacao().done(new DoneCallback&lt;ParametrosDeInicializacao&gt;() {
          @Override
          public void onDone(final ParametrosDeInicializacao param) {
              requestQueue.add(setDefaultRetryPolicy(new StringRequest(
                      Method.POST,
                      urlPara(GRAVAR_VENDA_MOBILE, usuarioAutenticado.getFilial(), usuarioAutenticado.getCodigo()),
                      listener(callback),
                      //errorListener(R.string.could_not_load_produtos, callback)
                      new ErrorListener() {
                          @Override
                          public void onErrorResponse(VolleyError error) {
                              callback.onError(new MessageCodeException(error.networkResponse.statusCode, error));
                          }
                      }
              ) {
  
                  @Override
                  public Map&lt;String, String&gt; getHeaders() throws AuthFailureError {
                      Map&lt;String, String&gt; headers = new HashMap&lt;String, String&gt;();
                      headers.put("Encoding", "UTF-8");
                      headers.put("Accept", "application/json");
                      headers.put("Content-type", "application/json; charset=UTF-8");
                      return headers;
                  }
  
  
              }));
          }
      });
  }
  </code></pre>
  
  <p>Retry Policy:</p>
  
  <pre><code>private Request&lt;?&gt; setDefaultRetryPolicy(Request&lt;?&gt; request) {
      request.setRetryPolicy(new DefaultRetryPolicy(30000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
  
      return request;
  }
  </code></pre>
  
  <p>Basically, I want to set the timeout to 30 secs with 0 retries. </p>
  
  <p>If I increase the number of retries it works as expected, but if I set it to 0 it makes 2 requests.</p>
  
  <p>Need some help here.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I managed to solve my issue by setting the keep-alive property to false inside android. eg:</p>
  
  <pre><code>System.setProperty("http.keepAlive", "false");
  </code></pre>
  
  <p>I added this line of code inside the class where I import requestqueue and make the requests.</p>
  
  <p>Also, check if you server has the keep-alive header.</p>
  
  <p>This <a href="https://stackoverflow.com/questions/3352424/httpurlconnection-openconnection-fails-second-time">post</a> helped get to the solution.</p>