You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Filip Hanik - Dev Lists <de...@hanik.com> on 2006/07/13 03:36:17 UTC

TC6, Response.recycle question

I have a question, I looked at the code for Response.java,
it seems that even if the Request and Response objects have been 
recycled, the ResponseFacade is allowed a reference all the way down to 
the output buffer.
If this output buffer happens to be reused somewhere, for a different 
socket, we  are now writing to the wrong browser.

In Response.java we have the following code:
   public void recycle() {

        outputBuffer.recycle();
        usingOutputStream = false;
        usingWriter = false;
        appCommitted = false;
        included = false;
        error = false;
        isCharacterEncodingSet = false;
       
        cookies.clear();

        if (Constants.SECURITY) {
            if (facade != null) {
                facade.clear(); //why does this only happen when the 
security manager is enabled?
                facade = null;
            }
            if (outputStream != null) {
                outputStream.clear();
                outputStream = null;
            }
            if (writer != null) {
                writer.clear();
                writer = null;
            }
        } else {
            writer.recycle();
        }

    }

would anyone want to explain why the facacde.clear() would only be 
called by with the security manager turned on,
The result of the reference still being valid, can appear when an error 
happens on incoming chunked data on a second or third comet request,
and since the comet still has the reference, it can still try to write, 
and in this case, the socket not being available yields the error,
but the byte buffer is filled up.

java.lang.NullPointerException
    at 
org.apache.coyote.http11.InternalNioOutputBuffer.flushBuffer(InternalNioOutputBuffer.java:723)
    at 
org.apache.coyote.http11.InternalNioOutputBuffer.flush(InternalNioOutputBuffer.java:290)
    at 
org.apache.coyote.http11.Http11NioProcessor.action(Http11NioProcessor.java:1015)
    at org.apache.coyote.Response.action(Response.java:182)
    at 
org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:294)
    at 
org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:268)
    at org.apache.catalina.connector.Response.flushBuffer(Response.java:530)
    at 
org.apache.catalina.connector.ResponseFacade.flushBuffer(ResponseFacade.java:277)
    at 
org.hanik.comet.test.TestCometServlet$MyCometThread.run(TestCometServlet.java:88)

I'm looking to be enlightened....

thanks
Filip


java.lang.NullPointerException (the blocking http connection)
    at 
org.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:772)
    at 
org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:123)
    at 
org.apache.coyote.http11.InternalOutputBuffer.doWrite(InternalOutputBuffer.java:579)
    at org.apache.coyote.Response.doWrite(Response.java:559)
    at 
org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:333)
    at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:433)
    at 
org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:289)
    at 
org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:268)
    at org.apache.catalina.connector.Response.flushBuffer(Response.java:530)
    at 
org.apache.catalina.connector.ResponseFacade.flushBuffer(ResponseFacade.java:277)
    at 
org.hanik.comet.test.TestCometServlet$MyCometThread.run(TestCometServlet.java:84)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: TC6, Response.recycle question

Posted by Filip Hanik - Dev Lists <de...@hanik.com>.
Remy Maucherat wrote:
> Filip Hanik - Dev Lists wrote:
>> I'm looking to be enlightened....
>
> You gave all the reason by yourself: this is an invalid access, so an 
> application bug. If there's no security manager, then it's not a 
> problem (the person is supposed to fix his bug), while if the security 
> manager is there, the performance hit is paid and security must be 
> enforced. \
fair enough!

Filip

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: TC6, Response.recycle question

Posted by Remy Maucherat <re...@apache.org>.
Filip Hanik - Dev Lists wrote:
> I'm looking to be enlightened....

You gave all the reason by yourself: this is an invalid access, so an 
application bug. If there's no security manager, then it's not a problem 
(the person is supposed to fix his bug), while if the security manager 
is there, the performance hit is paid and security must be enforced.

Rémy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org