Author: markt
Date: Wed May 18 17:25:28 2011
New Revision: 1124342

URL: http://svn.apache.org/viewvc?rev=1124342&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51197
Fix possible dropped connection when sendError or sendRedirst are used during 
async processing.

Modified:
    tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
    tomcat/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?rev=1124342&r1=1124341&r2=1124342&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Wed May 
18 17:25:28 2011
@@ -277,6 +277,9 @@ public class CoyoteAdapter implements Ad
                 if (ctxt != null) {
                     ctxt.fireRequestDestroyEvent(request);
                 }
+                // Lift any suspension (e.g. if sendError() was used by an 
async
+                // request
+                response.setSuspended(false);
             }
 
             if (status==SocketStatus.TIMEOUT) {

Modified: tomcat/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java?rev=1124342&r1=1124341&r2=1124342&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java 
(original)
+++ tomcat/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java Wed 
May 18 17:25:28 2011
@@ -49,6 +49,8 @@ public class TestAsyncContextImpl extend
     private static final long REQUEST_TIME = 500;
     // Timeout thread (where used) checks for timeout every second
     private static final long TIMEOUT_MARGIN = 1000;
+    // Default timeout for these tests
+    private static final long TIMEOUT = 3000;
 
     public void testBug49528() throws Exception {
         // Setup Tomcat instance
@@ -1112,4 +1114,74 @@ public class TestAsyncContextImpl extend
     }
     
 
+    public void testBug51197() throws Exception {
+        // Setup Tomcat instance
+        Tomcat tomcat = getTomcatInstance();
+        
+        // Must have a real docBase - just use temp
+        File docBase = new File(System.getProperty("java.io.tmpdir"));
+        
+        Context ctx = tomcat.addContext("", docBase.getAbsolutePath());
+
+        AsyncErrorServlet asyncErrorServlet =
+            new AsyncErrorServlet(HttpServletResponse.SC_BAD_REQUEST);
+        Wrapper wrapper =
+            Tomcat.addServlet(ctx, "asyncErrorServlet", asyncErrorServlet);
+        wrapper.setAsyncSupported(true);
+        ctx.addServletMapping("/asyncErrorServlet", "asyncErrorServlet");
+
+        TesterAccessLogValve alv = new TesterAccessLogValve();
+        ctx.getPipeline().addValve(alv);
+        
+        tomcat.start();
+        
+        StringBuilder url = new StringBuilder(48);
+        url.append("http://localhost:";);
+        url.append(getPort());
+        url.append("/asyncErrorServlet");
+        
+        int rc = getUrl(url.toString(), new ByteChunk(), null);
+        
+        assertEquals(HttpServletResponse.SC_BAD_REQUEST, rc);
+        
+        // Without this test may complete before access log has a chance to log
+        // the request
+        Thread.sleep(REQUEST_TIME);
+        
+        // Check the access log
+        validateAccessLog(alv, 1, HttpServletResponse.SC_BAD_REQUEST, TIMEOUT,
+                TIMEOUT + TIMEOUT_MARGIN + REQUEST_TIME);
+
+    }
+
+    private static class AsyncErrorServlet extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        private int status = 200;
+
+        public AsyncErrorServlet(int status) {
+            this.status = status;
+        }
+        
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+            
+            final AsyncContext actxt = req.startAsync();
+            actxt.setTimeout(TIMEOUT);
+            actxt.start(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        ((HttpServletResponse) actxt.getResponse()).sendError(
+                                status);
+                    } catch (IOException e) {
+                        // Ignore
+                    }
+                }
+            });
+        }
+    }
+
 }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1124342&r1=1124341&r2=1124342&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed May 18 17:25:28 2011
@@ -101,6 +101,10 @@
         get returned with requests mapped to a context with a path of
         <code>/foobar</code>. (markt)
       </fix>
+      <fix>
+        <bug>51197</bug>: Fix possible dropped connection when sendError or
+        sendRedirst are used during async processing. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">



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

Reply via email to