This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 7.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/7.0.x by this push: new 758e909 asyncStarted should be false once complete/dispatch in onError 758e909 is described below commit 758e909cb931b753b36afb1bfcc193a0699e9a43 Author: Mark Thomas <ma...@apache.org> AuthorDate: Fri Oct 11 14:25:17 2019 +0100 asyncStarted should be false once complete/dispatch in onError --- java/org/apache/coyote/AsyncStateMachine.java | 25 ++++++++-------- .../apache/catalina/core/TestAsyncContextImpl.java | 35 +++++++++++++++------- webapps/docs/changelog.xml | 3 +- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/java/org/apache/coyote/AsyncStateMachine.java b/java/org/apache/coyote/AsyncStateMachine.java index 8e2d8db..07f9b5c 100644 --- a/java/org/apache/coyote/AsyncStateMachine.java +++ b/java/org/apache/coyote/AsyncStateMachine.java @@ -274,7 +274,7 @@ public class AsyncStateMachine<S> { private synchronized boolean doComplete() { boolean triggerDispatch = false; - if (state == AsyncState.STARTING || state == AsyncState.ERROR) { + if (state == AsyncState.STARTING) { // Processing is on a container thread so no need to transfer // processing to a new container thread state = AsyncState.MUST_COMPLETE; @@ -287,10 +287,11 @@ public class AsyncStateMachine<S> { // request/response associated with the AsyncContext so need a new // container thread to process the different request/response. triggerDispatch = true; - } else if (state == AsyncState.TIMING_OUT) { - // Processing of timeouts can happen on or off a container thread - // (on is much more likely) but while in this state the call that - // triggers the timeout will be in progress on a container thread. + } else if (state == AsyncState.TIMING_OUT || state == AsyncState.ERROR) { + // Processing of timeouts and errors can happen on or off a + // container thread (on is much more likely) but while in this state + // the call that triggers the timeout will be in progress on a + // container thread. // The socket will be added to the poller when the container thread // exits the AbstractConnectionHandler.process() method so don't do // a dispatch here which would add it to the poller a second time. @@ -334,7 +335,7 @@ public class AsyncStateMachine<S> { private synchronized boolean doDispatch() { boolean triggerDispatch = false; - if (state == AsyncState.STARTING || state == AsyncState.ERROR) { + if (state == AsyncState.STARTING) { // Processing is on a container thread so no need to transfer // processing to a new container thread state = AsyncState.MUST_DISPATCH; @@ -347,13 +348,11 @@ public class AsyncStateMachine<S> { // request/response associated with the AsyncContext so need a new // container thread to process the different request/response. triggerDispatch = true; - } else if (state == AsyncState.TIMING_OUT) { - // Read/write operations can happen on or off a container thread but - // while in this state the call to listener that triggers the - // read/write will be in progress on a container thread. - // Processing of timeouts can happen on or off a container thread - // (on is much more likely) but while in this state the call that - // triggers the timeout will be in progress on a container thread. + } else if (state == AsyncState.TIMING_OUT || state == AsyncState.ERROR) { + // Processing of timeouts and errors can happen on or off a + // container thread (on is much more likely) but while in this state + // the call that triggers the timeout will be in progress on a + // container thread. // The socket will be added to the poller when the container thread // exits the AbstractConnectionHandler.process() method so don't do // a dispatch here which would add it to the poller a second time. diff --git a/test/org/apache/catalina/core/TestAsyncContextImpl.java b/test/org/apache/catalina/core/TestAsyncContextImpl.java index 2319ca7..461b1e1 100644 --- a/test/org/apache/catalina/core/TestAsyncContextImpl.java +++ b/test/org/apache/catalina/core/TestAsyncContextImpl.java @@ -679,6 +679,7 @@ public class TestAsyncContextImpl extends TomcatBaseTest { count ++; } Assert.assertEquals(expectedTrack, getTrack()); + Assert.assertTrue(dispatch.isAsyncStartedCorrect()); // Check the access log alv.validateAccessLog(1, 200, 0, REQUEST_TIME); @@ -689,13 +690,15 @@ public class TestAsyncContextImpl extends TomcatBaseTest { private static final long serialVersionUID = 1L; private static final String ITER_PARAM = "iter"; private static final String DISPATCH_CHECK = "check"; - private boolean addTrackingListener = false; - private boolean completeOnError = false; + private final TrackingListener trackingListener; public DispatchingServlet(boolean addTrackingListener, boolean completeOnError) { - this.addTrackingListener = addTrackingListener; - this.completeOnError = completeOnError; + if (addTrackingListener) { + trackingListener = new TrackingListener(completeOnError, true, null); + } else { + trackingListener = null; + } } @Override @@ -710,10 +713,8 @@ public class TestAsyncContextImpl extends TomcatBaseTest { track("DispatchingServletGet-"); final int iter = Integer.parseInt(req.getParameter(ITER_PARAM)) - 1; final AsyncContext ctxt = req.startAsync(); - if (addTrackingListener) { - TrackingListener listener = - new TrackingListener(completeOnError, true, null); - ctxt.addListener(listener); + if (trackingListener != null) { + ctxt.addListener(trackingListener); } Runnable run = new Runnable() { @Override @@ -732,6 +733,13 @@ public class TestAsyncContextImpl extends TomcatBaseTest { run.run(); } } + + public boolean isAsyncStartedCorrect() { + if (trackingListener == null) { + return true; + } + return trackingListener.isAsyncStartedCorrect(); + } } private static class NonAsyncServlet extends HttpServlet { @@ -1040,6 +1048,7 @@ public class TestAsyncContextImpl extends TomcatBaseTest { count ++; } Assert.assertEquals(expectedTrack, getTrack()); + Assert.assertTrue(dispatch.isAsyncStartedCorrect()); // Check the access log alv.validateAccessLog(1, 500, 0, REQUEST_TIME); @@ -1866,7 +1875,8 @@ public class TestAsyncContextImpl extends TomcatBaseTest { Tomcat tomcat = getTomcatInstance(); Context ctx = tomcat.addContext("", null); - Wrapper w = tomcat.addServlet("", "async", new Bug59219Servlet()); + Bug59219Servlet bug59219Servlet = new Bug59219Servlet(); + Wrapper w = tomcat.addServlet("", "async", bug59219Servlet); w.setAsyncSupported(true); ctx.addServletMapping("/async", "async"); @@ -1882,6 +1892,7 @@ public class TestAsyncContextImpl extends TomcatBaseTest { } Assert.assertEquals(expectedTrack, getTrack()); + Assert.assertTrue(bug59219Servlet.isAsyncStartedCorrect()); } @@ -1889,6 +1900,7 @@ public class TestAsyncContextImpl extends TomcatBaseTest { private static final long serialVersionUID = 1L; + private final TrackingListener trackingListener = new TrackingListener(true, false, "/async"); @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { @@ -1896,7 +1908,7 @@ public class TestAsyncContextImpl extends TomcatBaseTest { track("doGet-"); AsyncContext ctx = req.startAsync(); ctx.setTimeout(3000); - ctx.addListener(new TrackingListener(true, false, "/async")); + ctx.addListener(trackingListener); String loopsParam = req.getParameter("loops"); Integer loopsAttr = (Integer) req.getAttribute("loops"); @@ -1916,6 +1928,9 @@ public class TestAsyncContextImpl extends TomcatBaseTest { throw new ServletException(); } + public boolean isAsyncStartedCorrect() { + return trackingListener.isAsyncStartedCorrect(); + } } @Test diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index f02589e..82b4cc0 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -70,7 +70,8 @@ Ensure that <code>ServletRequest.isAsyncStarted()</code> returns <code>false</code> once <code>AsyncContext.complete()</code> or <code>AsyncContext.dispatch()</code> has been called during - <code>AsyncListener.onTimeout()</code>. (markt) + <code>AsyncListener.onTimeout()</code> or + <code>AsyncListener.onError()</code>. (markt) </fix> </changelog> </subsection> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org