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 2012/10/17 12:41:30 UTC

[Bug 54019] New: org.apache.coyote.Response & org.apache.coyote.Request don't call recycle() on notes[] elements.

https://issues.apache.org/bugzilla/show_bug.cgi?id=54019

          Priority: P2
            Bug ID: 54019
          Assignee: dev@tomcat.apache.org
           Summary: org.apache.coyote.Response & org.apache.coyote.Request
                    don't call recycle() on notes[] elements.
          Severity: critical
    Classification: Unclassified
          Reporter: frederic.arnoud@gmail.com
          Hardware: PC
            Status: NEW
           Version: unspecified
         Component: Connectors
           Product: Tomcat 7

Note: I'll use coyoteRequest (resp. coyoteResponse) where in code it's req
(resp. res), it just to help because there's also the connectorRequest (resp.
connectorResponse).

CoyoteAdapter checks coyoteRequest (resp. coyoteResponse) notes content in
CoyoteAdapter method service(coyoreRequest, coyoteResponse):
        Request request = (Request) req.getNote(ADAPTER_NOTES);
        Response response = (Response) res.getNote(ADAPTER_NOTES);

If they exist, it will not create a new one and set it as note in coyoteRequest
(resp. coyoteResponse):
        if (request == null) {
            ...
            // Set as notes
            req.setNote(ADAPTER_NOTES, request);
            res.setNote(ADAPTER_NOTES, response);
            ...
        }

There's no change later on theses notes, so recycle must work for them!

But (here the but): coyoteRequest (resp. coyoteResponse) will not recycle
theses notes.

Side effect of bug: in some cases (in my case it's for IOException while using
Comet API):
1) I can get the request attributes of previous request
2) My output buffer in response is corrupted, on first access like
setBufferSize I got an IllegalStateException buffer already commited (today I'm
not sure if it's the root cause, but now I can't reproduce it with my fix).
3) Side effect also on traditional servlet (and JSP for sure!).



Fix (for me, below a general fix):
==================================
I added this in org.apache.coyote.Request at end of recycle() method:
        for(Object note : notes) {
            if (note instanceof org.apache.catalina.connector.Request) {
                ((org.apache.catalina.connector.Request) note).recycle();
            }
        }

And this in org.apache.coyote.Response at end of recycle() method:
        for(Object note : notes) {
            if (note instanceof org.apache.catalina.connector.Response) {
                ((org.apache.catalina.connector.Response) note).recycle();
            }
        }



Final fix need a solution like (since notes will not use only connector Request
and Response):
1) Create a new Recyclable interface like:
public interface Recyclable {
        void recycle();
}

2) Change some object that could be used in notes (but maybe all recyclable
objects) to implements this interface:
        package org.apache.coyote;
        ...
        public final class Response implements Recyclable {
        ...
        }
and:
        package org.apache.coyote;
        ...
        public final class Request implements Recyclable {
        ...
        }

3) Do this in recycle method for org.apache.coyote.Request and Response:
        for(Object note : notes) {
            if (note instanceof Recyclable) {
                ((Recyclable) note).recycle();
            }
        }



IMPORTANT: THIS HAPPENS ALSO ON TOMCAT 6!



best regards
f.arnoud

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 54019] org.apache.coyote.Response & org.apache.coyote.Request don't call recycle() on notes[] elements.

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54019

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |normal

--- Comment #2 from Mark Thomas <ma...@apache.org> ---
Without a reproducible test case, this will eventually get resolved as invalid
on the assumption that the root cause is an application bug (there are plenty
of ways to trigger this sort of issue by retaining references across requests).

Based on the lack of response to my previous request for information, I am
reducing the severity to normal. If this really was critical then I'd expect a
faster response than 1 week+.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 54019] org.apache.coyote.Response & org.apache.coyote.Request don't call recycle() on notes[] elements.

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54019

--- Comment #3 from F.Arnoud <fr...@gmail.com> ---
I tried to extract the scheme of main application in a shorter test case.
But I cannot reproduce it.

1) For the buffer violation:
I can reproduce it but only if I don't respect the contract (using the buffer
after END/ERROR or after an IOException, it's a bug in the web application).

2) For the request attribute:
I cannot reproduce it, but in the customer application this attribute is set
only while processing the BEGIN event. And sometimes, this attribute contains a
previous setted value!

For case 1 or 2, even if it's a web application error, maybe Tomcat must
protect his buffer and attribute while it recycles object. I don't know the
philosophy, but IMHO something could be wrong here.

A solution, as an option, could be to wrap the servlet request and response and
disconnect it totally from background elements since application could use it
later. I talk about an option because this need to create new wrappers.

But without such wrapper, there's a problem with the recycling in a shared
server. I thought it was critical to be able to do this.

Personnaly I fixed this in my application with wrapper, anywhere an error
occurs I can completely separate running thread from the real tomcat objects.
In this application we have a lot of connections, some could be closed
while/before processing the begin event!

regards,
fred

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 54019] org.apache.coyote.Response & org.apache.coyote.Request don't call recycle() on notes[] elements.

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54019

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |RESOLVED
         Resolution|---                         |INVALID

--- Comment #4 from Mark Thomas <ma...@apache.org> ---
The option already exists. Try with starting Tomcat with
-Dorg.apache.catalina.connector.RECYCLE_FACADES=true

See http://tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html#Security

Given that the issue went away with a wrapper, that strongly suggests an
application error so I am closing this as invalid. If you find evidence that
points to a Tomcat bug feel free to re-open this.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 54019] org.apache.coyote.Response & org.apache.coyote.Request don't call recycle() on notes[] elements.

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54019

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO
                 OS|                            |All

--- Comment #1 from Mark Thomas <ma...@apache.org> ---
Recycling via the notes is not the answer.

The request and response objects should be correctly recycled between requests
in all circumstances. If you provide details of how to reproduce the issue you
saw with an IOException with Comet then this issue can be investigated and and
missing recycle calls added.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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