You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2002/06/07 13:47:22 UTC

DO NOT REPLY [Bug 9690] New: - POST - HttpRequestBase.parseParameters() infinite loop

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9690>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9690

POST - HttpRequestBase.parseParameters() infinite loop

           Summary: POST - HttpRequestBase.parseParameters() infinite loop
           Product: Tomcat 4
           Version: 4.0.2 Final
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Connector:Other
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: funkman@joedog.org


Summary:
org.apache.catalina.connector.HttpRequestBase.parseParameters() might inifinite
loop with POST data.

BACKGROUND:
We use apache 1.3 + tomcat 4.0.2 (Ajp13Connector).
We run 2 apache instances and 4 tomcat instances. Occasionally we see an httpd
process begin to *hog* cpu and not stop trying to hog cpu until httpd is
restarted. Over time, another httpd process will reach this state until too much
cpu is wasted on the bad httpd processes and a restart of apache is needed.
During this time - one (or more) of the java processes will also begin to hog
cpu. This is event does not happen quickly - it usually takes a week or so to
reach a state where a restart is needed. 
Looking at MRTG graphs - we see *lots* of network activity appear (and
disappear) with the start of the problem and subsequent restart of httpd.
I performed some thread dumps of the java process. And noticed that there were 2
threads consistently stuck in a similar stack trace. (Over the course of a 45
minute investigation of several thread dumps of the same java process).

Digging into the stack trace - I see that that the *runaway* threads are
switching between suspended/runnable and their method calls are socketRead and
socketWrite. 

I belive what is happening is an infinite loop in
HttpRequestBase.parseParameters(). Here is the the offending snippet, lines 639-647:
    int max = getContentLength();
    int max = getContentLength();
    int len = 0;
    byte buf[] = new byte[getContentLength()];
    ServletInputStream is = getInputStream();
    while (len < max) {
        int next = is.read(buf, len, max - len);
        len += next;
    }
== end sippet ==

I believe is.read is allowed to return 0 or a negative number. If that is true -
then the loop never finishes - possibly causing the issues I am seeing. It seems
occasionally for some reason - the POSTing of data from apache to tomcat seems
to be failing but the not serious enough to warrant an IOException.

Unfortuneately - I have not yet been able reproduce this in a lab environment
yet. I only see this issue occur in a production environment.

If anyone can validate this - I may be able to provide a patch.

Here is one of the stack traces (that the thread is stuck in):
"Ajp13Processor[12009][56]" daemon prio=9 tid=0x0143da98 nid=318 lwp_id=29393
runnable [0x6edc1000..0x6edbf478]
	at java.net.SocketOutputStream.socketWrite(Native Method)
	at java.net.SocketOutputStream.write(Unknown Source)
	at org.apache.ajp.Ajp13.send(Ajp13.java:525)
	at org.apache.ajp.RequestHandler.refillReadBuffer(RequestHandler.java:700)
	at org.apache.ajp.RequestHandler.doRead(RequestHandler.java:645)
	at org.apache.ajp.Ajp13.doRead(Ajp13.java:354)
	at org.apache.ajp.tomcat4.Ajp13InputStream.read(Ajp13InputStream.java:99)
	at
org.apache.catalina.connector.HttpRequestBase.parseParameters(HttpRequestBase.java:644)
	at
org.apache.catalina.connector.HttpRequestBase.getParameterMap(HttpRequestBase.java:695)
	at
org.apache.catalina.connector.RequestFacade.getParameterMap(RequestFacade.java:175)
	at
org.apache.catalina.core.ApplicationHttpRequest.setRequest(ApplicationHttpRequest.java:523)
	- locked <0x7733f990> (a java.util.HashMap)
	at
org.apache.catalina.core.ApplicationHttpRequest.<init>(ApplicationHttpRequest.java:126)
	at
org.apache.catalina.core.ApplicationDispatcher.wrapRequest(ApplicationDispatcher.java:918)
	at
org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:547)
	at
org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
	at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:819)
	at org.apache.jsp.prod_0005flist$jsp._jspService(prod_0005flist$jsp.java:96)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
	at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
	at com.armstrong.j2ee.filter.AWICookieFilter.doFilter(AWICookieFilter.java:78)
	at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
	at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
	at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
	at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
	at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
	at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
	at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
	at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
	at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
	at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
	at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
	at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
	at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
	at org.apache.ajp.tomcat4.Ajp13Processor.process(Ajp13Processor.java:429)
	at org.apache.ajp.tomcat4.Ajp13Processor.run(Ajp13Processor.java:495)
	at java.lang.Thread.run(Unknown Source)

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>