title: Android (Java) HttpURLConnection silent retry on 'read' timeout
body: <p>So I'm using <code>Google Volley</code> for HTTP request, which basically uses <code>Java</code>'s <code>HttpURLConnection</code>.</p>
  
  <p>According to my tests, the <strong>problem is this</strong>:<br>
  When the 'read' timeout on the <code>HttpURLConnection</code> reaches, a silent retry is executed before the connection is closed and the relevant exception thrown (<code>SocketTimeoutException</code>).</p>
  
  <p><strong>Note</strong> that:<br>
  - I noticed this error when using <code>HTTP POST</code> request.<br>
  - 'read' timeout is different than 'connect' timeout.<br>
  - If the 'read' timeout (set by calling <code>connection.setReadTimeout(int)</code>) is NOT set (0), or set to a greater value than <code>connection.setConnectTimeout(int)</code>, this error does not occur.<br>
  - This issue has been discussed, <a href="https://stackoverflow.com/questions/24417817/stopping-silent-retries-in-httpurlconnection">here</a> for example, but I haven't found any satisfying solution.<br>
  - A somewhat related issue can be found <a href="http://www.coderanch.com/t/490463/sockets/java/Timeout-retry-URLHTTPRequest" rel="noreferrer">here</a>, but I'm not sure it is relevant (is it?)</p>
  
  <p><strong>More Background</strong><br>
  My app is used for paying money, so not retrying a request is crucial (yes, I know it can be handled by the server, I want my client to be "correct" anyway).</p>
  
  <p>When the 'read' timeout is set, in case the server connection is established, but the server waits/sleeps/delays-response that 'timeout' time before answering (thus raising the 'read' exception and not the 'connect' exception), another (silent) request is sent just before that exception is raised, resulting in 2 similar requests, which is not acceptable.  </p>
  
  <p><strong>What kind of solution am I looking for?</strong><br>
  Well, a one that will nicely solve this problem/bug, just like the fix explained <a href="http://www.coderanch.com/t/490463/sockets/java/Timeout-retry-URLHTTPRequest" rel="noreferrer">here</a> (but I again, I think it's irrelevant in this case).<br>
  Also, I would want to keep the original flow as is, meaning not forcing the connection to close or anything like that.  </p>
  
  <p>What I'm gonna do for now, is set the 'read' timeout to twice the 'connection' timeout (they start counting at the same time), to make sure the 'connection' exception is raised first. I will also try to overcome this issue on the server side. The problem is, this 'read' timeout is there for a reason, and my current implementation practically just ignores it, and handles only 'connection' timeouts.  </p>
  
  <p><strong>EDIT</strong>
  The <code>Volley</code> library's <code>RetryPolicy</code> has not affect on this issue, as this is a silent retry.
  I looked as deep as possible inside the library. Logs/breakpoints everywhere, cancelled the calls to retry. That how I know it is 99.99% a <code>HttpURLConnection</code> issue.</p>