Tomcat 5.5.14 running with the latest mod_jk (1.2.15) + Apache 2.2.0 causes bizarre and buggy behavior with request.getReader(). This does NOT happen if the same jsp is accessed directly via localhost:8080 Consider the following JSP (called hello.jsp): ---------------------------start ----------------------- hello world <% out.println("2+2=" + (2+2)); out.print(request.getMethod()); out.print(" "); out.print(request.getRequestURI()); String s = request.getQueryString(); if (s != null) { out.print("?"); out.println(s); } out.print("<br>PATH_INFO=" + request.getPathInfo()); out.print("<br>PATH_TRANSLATED=" + request.getPathInfo()); out.print("<br>SERVLET_PATH=" + request.getServletPath()); out.print("<br>QUERY_STRING=" + request.getQueryString()); %> <h2>POST PARAMS</h2> <% java.io.Reader in = request.getReader(); int c = -1; while ( (c = in.read()) != -1) { out.print((char)c); System.out.print((char)c); } %> -------------------------------- end ------------------------------ This results in the following time out and stack trace. This is because the reader returned by request.getReader() DOES NOT return -1 -------------------------- start ------------------------------------------------- HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: Exception in JSP: /hello.jsp:22 19: <% 20: java.io.Reader in = request.getReader(); 21: int c = -1; 22: while ( (c = in.read()) != -1) { 23: out.print((char)c); 24: System.out.print((char)c); 25: } Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:381) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) root cause java.net.SocketTimeoutException: Read timed out java.net.SocketInputStream.socketRead0(Native Method) java.net.SocketInputStream.read(SocketInputStream.java:129) java.io.BufferedInputStream.fill(BufferedInputStream.java:218) java.io.BufferedInputStream.read1(BufferedInputStream.java:256) java.io.BufferedInputStream.read(BufferedInputStream.java:313) org.apache.jk.common.ChannelSocket.read(ChannelSocket.java:607) org.apache.jk.common.ChannelSocket.receive(ChannelSocket.java:545) org.apache.jk.common.JkInputStream.receive(JkInputStream.java:184) org.apache.jk.common.JkInputStream.doRead(JkInputStream.java:163) org.apache.coyote.Request.doRead(Request.java:423) org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:283) org.apache.catalina.connector.InputBuffer.realReadChars(InputBuffer.java:329) org.apache.tomcat.util.buf.CharChunk.substract(CharChunk.java:382) org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:351) org.apache.catalina.connector.CoyoteReader.read(CoyoteReader.java:92) org.apache.jsp.hello_jsp._jspService(org.apache.jsp.hello_jsp:64) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) ---------------------------------- end ------------------------- Here is the mod_jk.conf file: LoadModule jk_module modules/mod_jk.so JkWorkersFile /usr/local/tomcat/conf/worker.properties JkLogFile /usr/local/tomcat/logs/mod_jk.log JkLogLevel info JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " JkRequestLogFormat "%s %w %V %T %s" JkOptions +ForwardURICompat JkOptions +ForwardDirectories JkMount /*.jsp w1 JkMount /*/servlet/ w1 JkMount /*.page w1 And here is worker.properties: worker.list=w1,jkstatus worker.maintain=120 worker.w1.type=ajp13 worker.w1.host=localhost worker.w1.port=8009 worker.w1.socket_timeout=120 worker.w1.recycle_timeout=500 worker.jkstatus.type=status
getInputStream() has the same problem, so this is not just Reader related. With either request.getInputStream() or request.getReader(), the read() method times out. It should return -1 immediately if there is no data. This is a serious bug.
After a lot of testing, this is what I've found: 1) This bug exists with both apache 2.0.55 and 2.2.0 running against tomcat 5.5.14/5.512 2) However, this bug does NOT exist with tomcat 5.0.30 (with either version of apache). The same version (mod jk 1.2.15) was used for all tests. Therefore, this is a serious bug with 5.5.14 (and also 5.5.12) + mod jk 1.2.15 + apache 2.x
This is fixed in the SVN trunk, and will appear in 5.5.15.
>> This is fixed in the SVN trunk, and will appear in 5.5.15. Isn't this a critical bug that should be fixed in 5.5.12 and 5.5.14 as well ? After all, not being able to get the request InputStream or Reader AT ALL is pretty darn bad,
That isn't how Tomcat releases work. Bugs in 5.5.x get fixed in a future 5.5.x release. We don't release patches for fixes against previous versions.
*** Bug 37885 has been marked as a duplicate of this bug. ***