This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit ee83aed6ded79ab802d17bb8d51ad428eb1a2e45
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Oct 9 21:54:37 2019 +0100

    Don't trigger an additional dispatch with async I/O and complete
---
 java/org/apache/coyote/AsyncStateMachine.java | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/java/org/apache/coyote/AsyncStateMachine.java 
b/java/org/apache/coyote/AsyncStateMachine.java
index 3f2d2a2..cfc071a 100644
--- a/java/org/apache/coyote/AsyncStateMachine.java
+++ b/java/org/apache/coyote/AsyncStateMachine.java
@@ -320,19 +320,27 @@ public class AsyncStateMachine {
 
     private synchronized boolean doComplete() {
         clearNonBlockingListeners();
-        boolean doComplete = false;
+        boolean triggerDispatch = false;
         if (state == AsyncState.STARTING || state == AsyncState.TIMING_OUT ||
-                state == AsyncState.ERROR || state == 
AsyncState.READ_WRITE_OP) {
+                state == AsyncState.ERROR) {
             state = AsyncState.MUST_COMPLETE;
         } else if (state == AsyncState.STARTED || state == 
AsyncState.COMPLETE_PENDING) {
             state = AsyncState.COMPLETING;
-            doComplete = true;
+            triggerDispatch = true;
+        } else if (state == AsyncState.READ_WRITE_OP) {
+            // Read/write operations can happen on or off a container thread 
but
+            // the call to listener that triggers the read/write will always be
+            // on a container thread and the socket will be added to the poller
+            // when the thread exits the AbstractConnectionHandler.process()
+            // method so don't do a dispatch here which would add it to the
+            // poller a second time.
+            state = AsyncState.COMPLETING;
         } else {
             throw new IllegalStateException(
                     sm.getString("asyncStateMachine.invalidAsyncState",
                             "asyncComplete()", state));
         }
-        return doComplete;
+        return triggerDispatch;
     }
 
 
@@ -366,7 +374,7 @@ public class AsyncStateMachine {
 
     private synchronized boolean doDispatch() {
         clearNonBlockingListeners();
-        boolean doDispatch = false;
+        boolean triggerDispatch = false;
         if (state == AsyncState.STARTING ||
                 state == AsyncState.TIMING_OUT ||
                 state == AsyncState.ERROR) {
@@ -381,22 +389,22 @@ public class AsyncStateMachine {
             // If on a container thread the current request/response are not 
the
             // request/response associated with the AsyncContext so need a new
             // container thread to process the different request/response.
-            doDispatch = true;
+            triggerDispatch = true;
         } else if (state == AsyncState.READ_WRITE_OP) {
             state = AsyncState.DISPATCHING;
             // If on a container thread then the socket will be added to the
-            // poller poller when the thread exits the
+            // poller when the thread exits the
             // AbstractConnectionHandler.process() method so don't do a 
dispatch
             // here which would add it to the poller a second time.
             if (!ContainerThreadMarker.isContainerThread()) {
-                doDispatch = true;
+                triggerDispatch = true;
             }
         } else {
             throw new IllegalStateException(
                     sm.getString("asyncStateMachine.invalidAsyncState",
                             "asyncDispatch()", state));
         }
-        return doDispatch;
+        return triggerDispatch;
     }
 
 


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

Reply via email to