title: Some Android clients disconnect and then retry HTTP request after 15 seconds, even though timeout is larger
body: <p>I have an Android app that makes HTTP requests to a server, which I control. This server relays the requests to another server, which I don't control and is currently severely overloaded. In order to cope with the delays in the remote server, I have increased all timeouts I am aware of.</p>
  
  <p>In my own server, I am seeing some clients (the Android app) abort the HTTP request after 15 seconds and then retry the same request, even though I have set the connection and read timeouts to be be much larger than that.</p>
  
  <p>nginx in my server reports that as a 499 error in the logs, and it always happens around 15 seconds after the request arrived.</p>
  
  <p>Using wireshark on my server, I have positively verified that it is the client disconnecting (in sends a FIN packet) and then immediately retrying the same request.</p>
  
  <p>I haven't been able to reproduce the problem using my own phone. Even if I make the server introduce an artificial delay, my phone respects the timeout I have set. On a recent update I started sending some basic information about the user (phone model, android version, current connection type) to see if I can detect a pattern for the problematic phones, but haven't noticed any pattern so far.</p>
  
  <p>I was previously using <code>HttpClient</code> on the app, and tried several approaches to correct this problem, but the timeouts and retries kept happening. Then I switched to <code>HttpURLConnection</code>, and I'm seeing the same behavior. The <code>HttpURLConnection</code> version of the code is really simple, almost verbatim from the examples, save for different timeout values:</p>
  
  <pre><code>InputStream is = null;
  try
  {
    URL url = new URL("my.server.com" + paramString);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setReadTimeout(180 * 1000);
    conn.setConnectTimeout(30 * 1000);
    conn.setRequestMethod("GET");
    conn.setDoInput(true);
    conn.connect();
  
    int response = conn.getResponseCode();
    is = conn.getInputStream();
  }
  </code></pre>
  
  <p>I have found no mention of this behavior anywhere on the documentation. Any ideas on where this 15 seconds timeout is being set and why my own timeout aren't respected?</p>