title: JBOSS hanging on org.apache.jk.common.JkInputStream.receive() - IOException reading the HTTP request InputStream
body: <p>I have a problem that causes all threads in JBOSS to block while reading the input stream. It does not happen predictably and the system can run for days (or longer) before it starts to suffer.</p>
  
  <p>The problem looks similar to <a href="https://stackoverflow.com/questions/1624159">this</a> question, but I have yet to try setting <code>-Dhttp.keepAlive=false</code> as recommended in the answer because I wondered if anyone else has a different/better solution. I would rather not have to incur a performance hit by setting this property to false (assuming that even fixes the problem).</p>
  
  <p>There are some Sun bugs that talk about issues with <code>BufferedReader</code> and <code>InputStream</code> reading (<a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6192696" rel="nofollow noreferrer">bug 6192696</a>, <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6409506" rel="nofollow noreferrer">bug 6409506</a>), but to me they seem a bit inconclusive. Your thoughts/advice/experience with an issue like this and the Sun bugs would be welcome.</p>
  
  <p>Here is the Exception:</p>
  
  <pre class="lang-none prettyprint-override"><code>java.io.IOException
      at org.apache.jk.common.JkInputStream.receive(JkInputStream.java:190)
      at org.apache.jk.common.JkInputStream.refillReadBuffer(JkInputStream.java:249)
      at org.apache.jk.common.JkInputStream.doRead(JkInputStream.java:168)
      at org.apache.coyote.Request.doRead(Request.java:418)
      at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:284)
      at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:404)
      at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:299)
      at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:192)
      at com.vicinity.ExtractMessageServlet.service(ExtractMessageServlet.java:62)
      ...
  </code></pre>
  
  <p>Here is a sample of the request headers:</p>
  
  <pre class="lang-none prettyprint-override"><code>POST http: //www.xyz.com HTTP/1.0
  Host: www.xyz.com:80
  Accept: */*
  Content-Type: application/octet-stream
  Content-Length: 00597
  Session-Key: 812a0000
  </code></pre>
  
  <p>Here is the <code>Servlet</code> code of the web application. It get's stuck on <code>servletInputStream.read</code>:</p>
  
  <pre><code>int lengthOfBuffer = request.getContentLength();
  byte[] buffer = new byte[lengthOfBuffer];
  ByteArrayOutputStream output = new ByteArrayOutputStream(lengthOfBuffer);
  ServletInputStream servletInputStream = request.getInputStream();
  int readBytes = -1;
  while ((readBytes = servletInputStream.read(buffer, 0, lengthOfBuffer)) != -1) {
      output.write(buffer, 0, readBytes);
  }
  byte[] inputStream = output.toByteArray();
  ...
  // Continue to process the input stream
  </code></pre>
  
  <p>JBoss version: JBoss AS 4.0.5.GA.<br>
  Also, <code>mod_jk</code> is routing HTTP requests on port 80 from Apache server to the JBoss server - if that's of interest.</p>