Author: kkolinko
Date: Mon May 19 13:37:45 2014
New Revision: 1595900

URL: http://svn.apache.org/r1595900
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56399
When recycling a Coyote request, ensure that Catalina request have been 
recycled.

Merged r1594436 r1594924 r1595887 from tomcat/trunk.

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
    
tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/LocalStrings.properties
    tomcat/tc7.0.x/trunk/java/org/apache/coyote/Adapter.java
    tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java
    
tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1594436,1594924,1595887

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?rev=1595900&r1=1595899&r2=1595900&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 
Mon May 19 13:37:45 2014
@@ -524,6 +524,44 @@ public class CoyoteAdapter implements Ad
     }
 
 
+    private static class RecycleRequiredException extends Exception {
+        private static final long serialVersionUID = 1L;
+    }
+
+    @Override
+    public void checkRecycled(org.apache.coyote.Request req,
+            org.apache.coyote.Response res) {
+        Request request = (Request) req.getNote(ADAPTER_NOTES);
+        Response response = (Response) res.getNote(ADAPTER_NOTES);
+        String messageKey = null;
+        if (request != null && request.getHost() != null) {
+            messageKey = "coyoteAdapter.checkRecycled.request";
+        } else if (response != null && response.getContentWritten() != 0) {
+            messageKey = "coyoteAdapter.checkRecycled.response";
+        }
+        if (messageKey != null) {
+            // Log this request, as it has probably skipped the access log.
+            // The log() method will take care of recycling.
+            log(req, res, 0L);
+
+            if (connector.getState().isAvailable()) {
+                if (log.isInfoEnabled()) {
+                    log.info(sm.getString(messageKey),
+                            new RecycleRequiredException());
+                }
+            } else {
+                // There may be some aborted requests.
+                // When connector shuts down, the request and response will not
+                // be reused, so there is no issue to warn about here.
+                if (log.isDebugEnabled()) {
+                    log.debug(sm.getString(messageKey),
+                            new RecycleRequiredException());
+                }
+            }
+        }
+    }
+
+
     @Override
     public String getDomain() {
         return connector.getDomain();

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/LocalStrings.properties?rev=1595900&r1=1595899&r2=1595900&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/LocalStrings.properties 
(original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/LocalStrings.properties 
Mon May 19 13:37:45 2014
@@ -36,6 +36,8 @@ coyoteConnector.parseBodyMethodNoTrace=T
 #
 coyoteAdapter.read=The servlet did not read all available bytes during the 
processing of the read event
 coyoteAdapter.parsePathParam=Unable to parse the path parameters using 
encoding [{0}]. The path parameters in the URL will be ignored.
+coyoteAdapter.checkRecycled.request=Encountered a non-recycled request and 
recycled it forcedly.
+coyoteAdapter.checkRecycled.response=Encountered a non-recycled response and 
recycled it forcedly.
 coyoteAdapter.debug=The variable [{0}] has value [{1}]
 coyoteAdapter.accesslogFail=Exception while attempting to add an entry to the 
access log
 

Modified: tomcat/tc7.0.x/trunk/java/org/apache/coyote/Adapter.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/coyote/Adapter.java?rev=1595900&r1=1595899&r2=1595900&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/coyote/Adapter.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/coyote/Adapter.java Mon May 19 
13:37:45 2014
@@ -56,6 +56,19 @@ public interface Adapter {
     public void log(Request req, Response res, long time);
 
     /**
+     * Assert that request and response have been recycled. If they have not
+     * then log a warning and force a recycle. This method is called as a 
safety
+     * check when a processor is being recycled and may be returned to a pool
+     * for reuse.
+     *
+     * @param req
+     *            Request
+     * @param res
+     *            Response
+     */
+    public void checkRecycled(Request req, Response res);
+
+    /**
      * Provide the name of the domain to use to register MBeans for conponents
      * associated with the connector.
      * 

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java?rev=1595900&r1=1595899&r2=1595900&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java 
Mon May 19 13:37:45 2014
@@ -585,6 +585,8 @@ public abstract class AbstractAjpProcess
      */
     @Override
     public void recycle(boolean socketClosing) {
+        getAdapter().checkRecycled(request, response);
+
         asyncStateMachine.recycle();
 
         // Recycle Request object

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java?rev=1595900&r1=1595899&r2=1595900&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java 
(original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java 
Mon May 19 13:37:45 2014
@@ -1764,6 +1764,8 @@ public abstract class AbstractHttp11Proc
 
     @Override
     public final void recycle(boolean isSocketClosing) {
+        getAdapter().checkRecycled(request, response);
+
         if (getInputBuffer() != null) {
             getInputBuffer().recycle();
         }

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1595900&r1=1595899&r2=1595900&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Mon May 19 13:37:45 2014
@@ -196,6 +196,10 @@
   </subsection>
   <subsection name="Coyote">
     <changelog>
+      <add>
+        <bug>56399</bug>: Assert that both Coyote and Catalina request objects
+        have been properly recycled. (kkolinko)
+      </add>
       <fix>
         <bug>56416</bug>: Correct documentation for default value of socket
         linger for the AJP and HTTP connectors. (markt)



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

Reply via email to