title: .read() throws intermittent SocketTimeoutException even though data should be there
body: <p>I'm working on a web server for Android and even though I've spent days trying to fix it, I'm at my wits' end with this particular bug. I'm trying to read the request from the browser, and the code works fine most of the time, but something like 5% of the requests fail and it throws random SocketTimeoutExceptions without even reading a single character from the Socket.</p>
  
  <p>I have tested this with different browsers and it happens with all of them, so chances are the problem is on my end. Here's the relevant code, stripped down as far as possible:</p>
  
  <pre><code>public class ServerThread extends Thread {
  
  private ServerSocket ss = null;
  private boolean isRunning;
  
  private ExecutorService threadPool = new ThreadPoolExecutor(2, 12,
            60L, TimeUnit.SECONDS,
            new SynchronousQueue&lt;Runnable&gt;(),
            Executors.defaultThreadFactory(), 
            new ThreadPoolExecutor.CallerRunsPolicy());
  
  public ServerThread() {
  }
  
  public synchronized void run() {
      ss = new ServerSocket(8080, 1);
      isRunning = true;
  
      while (isRunning) {
          Socket clientSocket = null;
  
          try {
              if (ss != null) {
                  clientSocket = ss.accept();
                  if (isRunning) {
                      this.threadPool.execute(new HTTPSession(clientSocket));
                  }
              }
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  }
  }
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>public class HTTPSession implements Runnable {
  
  private Socket mSocket = null;
  
  public HTTPSession (Socket s) {
      mSocket = s;
  }
  
  
  public void run() {
  
      InputStream ips = null;
  
      try {
          mSocket.setSoTimeout(15000);
          ips = mSocket.getInputStream();
          ips.read();
      }
      catch (Exception e) {
          e.printStackTrace();
          Log.v("HTTPSession", "Socket connected: " + mSocket.isConnected() + ", Socket closed: " + mSocket.isClosed() + ", InputShutdown: " + mSocket.isInputShutdown());
      }
      finally {
              try { ips.close(); } catch (IOException ioe) {  }
              try { mSocket.close(); } catch (IOException ioe) {  }
      }
  
  }
  }
  </code></pre>
  
  <p>So ServerThread accepts the connection, HTTPSession tries to read from the Socket and sometimes it throws the SocketTimeoutException after the 15 seconds are up.</p>
  
  <p>The output from the Log statement in the catch in this case is:
      Socket connected: true, Socket closed: false, InputShutDown: false</p>
  
  <p>What gives? Surely 15 seconds is enough of a wait and it seems unlikely that mainstream web browsers just aren't sending any data, so why can't I read it?</p>
  
  <p>I would appreciate any input on this problem.</p>