Bug 27447 - CoyoteReader.readLine() read ahead problems
Summary: CoyoteReader.readLine() read ahead problems
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 5.0.19
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-03-04 18:09 UTC by Robert D. Birch
Modified: 2005-03-20 17:06 UTC (History)
0 users



Attachments
These are some files with text to test. We actually use XML, but these should suffice (842 bytes, application/x-zip-compressed)
2004-03-08 21:22 UTC, Robert D. Birch
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Robert D. Birch 2004-03-04 18:09:10 UTC
When posting utf-8 data with either \r\n or \n and that data exceeds the 
MAX_LINE_LENGTH the following I/O exception occurs:
Servlet threw exception
java.io.IOException
	at org.apache.coyote.tomcat5.InputBuffer.reset(InputBuffer.java:463)
	at org.apache.coyote.tomcat5.CoyoteReader.reset(CoyoteReader.java:153)
	at org.apache.coyote.tomcat5.CoyoteReader.readLine
(CoyoteReader.java:207)
	at symhttp.DBRActivationServlet.doPost(DBRActivationServlet.java:31)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:284)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:204)
	at org.apache.catalina.core.StandardWrapperValve.invoke
(StandardWrapperValve.java:257)
	at org.apache.catalina.core.StandardValveContext.invokeNext
(StandardValveContext.java:151)
	at org.apache.catalina.core.StandardPipeline.invoke
(StandardPipeline.java:567)
	at org.apache.catalina.core.StandardContextValve.invokeInternal
(StandardContextValve.java:245)
	at org.apache.catalina.core.StandardContextValve.invoke
(StandardContextValve.java:199)
	at org.apache.catalina.core.StandardValveContext.invokeNext
(StandardValveContext.java:151)
	at org.apache.catalina.core.StandardPipeline.invoke
(StandardPipeline.java:567)
	at org.apache.catalina.core.StandardHostValve.invoke
(StandardHostValve.java:184)
	at org.apache.catalina.core.StandardValveContext.invokeNext
(StandardValveContext.java:151)
	at org.apache.catalina.valves.ErrorReportValve.invoke
(ErrorReportValve.java:164)
	at org.apache.catalina.core.StandardValveContext.invokeNext
(StandardValveContext.java:149)
	at org.apache.catalina.core.StandardPipeline.invoke
(StandardPipeline.java:567)
	at org.apache.catalina.core.StandardEngineValve.invoke
(StandardEngineValve.java:156)
	at org.apache.catalina.core.StandardValveContext.invokeNext
(StandardValveContext.java:151)
	at org.apache.catalina.core.StandardPipeline.invoke
(StandardPipeline.java:567)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
	at org.apache.coyote.tomcat5.CoyoteAdapter.service
(CoyoteAdapter.java:206)
	at org.apache.coyote.http11.Http11Processor.process
(Http11Processor.java:833)
	at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnectio
n(Http11Protocol.java:732)
	at org.apache.tomcat.util.net.TcpWorkerThread.runIt
(PoolTcpEndpoint.java:619)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run
(ThreadPool.java:688)
	at java.lang.Thread.run(Thread.java:536)

If there are NO \r\n or \n then there is no problem sending data greater than 
MAX_LINE_LENGTH. 

Here is my servlet test code:public void doPost(HttpServletRequest request, 
HttpServletResponse response)
throws ServletException, IOException {
    response.setContentType(CONTENT_TYPE);

    System.out.println("Reading body data\n");
    String contentLen = request.getHeader("Content-Length");
    if ( contentLen != null ) {
      System.out.println("String Content-Length: " + contentLen);
      BufferedReader br = request.getReader();
      String in = null;
      while ( (in = br.readLine()) != null ){
        System.out.println(in);
      }
    } else {
      System.out.println("Null content-length");
    }
    PrintWriter out = response.getWriter();
    sendStuff(out);
  }
  //Clean up resources
  public void destroy() {
  }

I think the problem area is in CoyoteReader.readLine() and the handling of \n 
and \r\n. This seems to be around lines  178 - 194 of  
org.apache.coyote.tomcat5.CoyoteReader.java. 

Problem occurred first in 5.0.16, did an upgrade and still had the problem in 
5.0.19, tried it in some version of Tomcat 4 and had no problems.
Comment 1 Remy Maucherat 2004-03-04 18:23:03 UTC
I will try to fix this.
I recommend however that you attempt to design stuff more efficiently. Your web
application is very likely slow.
Comment 2 Remy Maucherat 2004-03-05 13:09:30 UTC
The bug is likely fixed, but this could cause regressions. Please test it.
Comment 3 Robert D. Birch 2004-03-08 21:16:27 UTC
Thanks for the speedy work, but the problem still exists. I have attached 6 
test files and a simple test servlet. If I send these test files using our http 
client or the curl http client the results are the same. The curl command line 
I use is:

curl -F "name=@postBigLine.txt" http://localhost:8082/Test/TestServlet

Thanks
Comment 4 Robert D. Birch 2004-03-08 21:22:35 UTC
Created attachment 10712 [details]
These are some files with text to test. We actually use XML, but these should suffice