Hello Tomcat Users and Committers,Platform: Tomcat 4.1, Linux ES 2.1,
jdk1.4.1.06Here is a snippet of the stack trace we regularly in our Tomcat
4.1.24 logs.----- Root Cause -----java.lang.IllegalStateException:
getOutputStream() has already been called for this response at
org.apache.catalina.connector.ResponseBase.getWriter(ResponseBase.java:756)
at
org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:174)
at
org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:173)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:166)
at
org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:184)
at
org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:198)
at
org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:193)
at
org.apache.jsp.ViewAttachment_jsp._jspService(ViewAttachment_jsp.java:76)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)We
intend to migrate to Tomcat 5.x later this year. In the interim, we recently
linked this exception event to leaked memory. That is, the
PageContextImpl.release() method (6th from top in stack trace, body below)
never completes as it does not catch the IllegalStateException that happens
when ResponseBase.getWriter()is called in the scope of flushBuffer().
public void release() { out = baseOut; try { if (isIncluded) {
((JspWriterImpl)out).flushBuffer(); // push it into the
including jspWriter } else { // Do not flush the buffer
even if we're not included (i.e. // we are the main page. The
servlet will flush it and close // the stream.
((JspWriterImpl)out).flushBuffer(); } } catch (IOException ex)
{ loghelper.log("Internal error flushing the buffer in release()");
} servlet = null; config = null; context = null;
needsSession = false; errorPageURL = null; bufferSize =
JspWriter.DEFAULT_BUFFER; autoFlush = true; request = null;
response = null; depth = -1; baseOut.recycle(); session =
null; attributes.clear(); }The tear-down activity session=null is skipped
because of the exception, which creates a problem since the session so
referenced becomes ineligible for garbage collection after processing the
request.Does anyone know:a) is this documented somewhere (I read 102 matches
for ‘memory leak’ on the Tomcat 4.1 list archives, but I did not find this
exact problem, except for an entry in the 4.1 release notes where it is
reported fixed in 4.1.20).b) is there a patch available to fix this in Tomcat
4.x?Thanks very much for your time,