Author: markt
Date: Sat Sep  8 15:12:21 2012
New Revision: 1382315

URL: http://svn.apache.org/viewvc?rev=1382315&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53843
request.isAsyncStarted() must continue to return true until the 
dispatch/complete actually happens (which at the earliest isn't until the 
thread where startAsync() was called returns to the container).

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/coyote/AsyncStateMachine.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1382314

Modified: tomcat/tc7.0.x/trunk/java/org/apache/coyote/AsyncStateMachine.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/coyote/AsyncStateMachine.java?rev=1382315&r1=1382314&r2=1382315&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/coyote/AsyncStateMachine.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/coyote/AsyncStateMachine.java Sat Sep  
8 15:12:21 2012
@@ -96,10 +96,10 @@ public class AsyncStateMachine<S> {
         DISPATCHED(false, false, false),
         STARTING(true, true, false),
         STARTED(true, true, false),
-        MUST_COMPLETE(true, false, false),
+        MUST_COMPLETE(true, true, false),
         COMPLETING(true, false, false),
         TIMING_OUT(true, false, false),
-        MUST_DISPATCH(true, false, true),
+        MUST_DISPATCH(true, true, true),
         DISPATCHING(true, false, true),
         ERROR(true,false,false);
     

Modified: 
tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java?rev=1382315&r1=1382314&r2=1382315&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java 
(original)
+++ 
tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestAsyncContextImpl.java 
Sat Sep  8 15:12:21 2012
@@ -1368,4 +1368,90 @@ public class TestAsyncContextImpl extend
         }
     }
 
+    @Test
+    public void testBug53843() 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());
+        Bug53843ServletA servletA = new Bug53843ServletA();
+        Wrapper a = Tomcat.addServlet(ctx, "ServletA", servletA);
+        a.setAsyncSupported(true);
+        Tomcat.addServlet(ctx, "ServletB", new Bug53843ServletB());
+
+        ctx.addServletMapping("/ServletA", "ServletA");
+        ctx.addServletMapping("/ServletB", "ServletB");
+
+        tomcat.start();
+
+        StringBuilder url = new StringBuilder(48);
+        url.append("http://localhost:";);
+        url.append(getPort());
+        url.append("/ServletA");
+
+        ByteChunk body = new ByteChunk();
+        int rc = getUrl(url.toString(), body, null);
+
+        assertEquals(HttpServletResponse.SC_OK, rc);
+        assertEquals("OK", body.toString());
+        assertTrue(servletA.isAsyncWhenExpected());
+    }
+
+    private static class Bug53843ServletA extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        private boolean isAsyncWhenExpected = true;
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+
+            // Should not be async at this point
+            isAsyncWhenExpected = isAsyncWhenExpected && !req.isAsyncStarted();
+
+            final AsyncContext async = req.startAsync();
+
+            // Should be async at this point
+            isAsyncWhenExpected = isAsyncWhenExpected && req.isAsyncStarted();
+
+            async.start(new Runnable() {
+
+                @Override
+                public void run() {
+                    // This should be delayed until the original container
+                    // thread exists
+                    async.dispatch("/ServletB");
+                }
+            });
+
+            try {
+                Thread.sleep(3000);
+            } catch (InterruptedException e) {
+                throw new ServletException(e);
+            }
+
+            // Should be async at this point
+            isAsyncWhenExpected = isAsyncWhenExpected && req.isAsyncStarted();
+        }
+
+        public boolean isAsyncWhenExpected() {
+            return isAsyncWhenExpected;
+        }
+    }
+
+    private static class Bug53843ServletB extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+            resp.setContentType("text/plain");
+            resp.getWriter().print("OK");
+        }
+    }
 }

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=1382315&r1=1382314&r2=1382315&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Sat Sep  8 15:12:21 2012
@@ -69,6 +69,12 @@
         <code>invokeAndSet</code>code>, <code>invokeAndGet</code>,
         etc. (schultz)
       </update>
+      <fix>
+        <bug>53843</bug>: <code>request.isAsyncStarted()</code> must continue 
to
+        return true until the dispatch/complete actually happens (which at the
+        earliest isn't until the thread where <code>startAsync()</code> was
+        called returns to the container). (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