title: Timeout has no limit? - HttpsURLConnection
body: <p>In my Java client app I'm connecting to my server using HttpsURLConnection. This works all fine, except on certain moments it does not timeout at all. I set the timeout parameters of the connection as such (to 5000 ms):</p>
  
  <pre><code>HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
  
  // timeouts
  con.setConnectTimeout(5000);
  con.setReadTimeout(5000);
  
  con.setRequestMethod("put");
  con.setDoInput(true);
  con.setDoOutput(true);
  con.setRequestProperty("Content-length", String.valueOf(output.length()));
  OutputStreamWriter os = new OutputStreamWriter(con.getOutputStream(), "UTF-8");
  BufferedWriter writer = new BufferedWriter(os);
  writer.write(output);
  writer.close();
  os.close();
  
  con.connect();
  
  int respCode = con.getResponseCode();
  
  if(respCode == 200) {
          InputStreamReader is = new InputStreamReader(con.getInputStream());
          BufferedReader br = new BufferedReader(is);
          String input;
          String respBody = "";
          while ((input = br.readLine()) != null){
              respBody += input;
          }
          br.close();
          is.close();
          this.result = respBody;
  }
  </code></pre>
  
  <p>I'm catching all exceptions, but none is registered, so the problem cannot be an uncaught exception. The connection simply does not timeout. I waited for 3 minutes and had no response. I could reproduce the bug a few times while switching network during the execution of a request.</p>
  
  <p>Also, sometimes there was a response after about a minute. Which is longer than the timeouts.</p>
  
  <p>I already tried interrupting the thread on which the request is made after a timeout, disconnecting the HttpsURLConnection. But there must be a neater solution than that. I would like to know where this indefinite timeout comes from.</p>
  
  <p>Any ideas? </p>
  
  <p>Thanks a lot!</p>