You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2021/03/25 17:52:40 UTC

[tomcat] branch master updated: Re-work fix for complete()/dispatch() when in READ_WRITE state

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

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


The following commit(s) were added to refs/heads/master by this push:
     new a417690  Re-work fix for complete()/dispatch() when in READ_WRITE state
a417690 is described below

commit a417690be308ca145a8b5b61f0260a4f713ea331
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Mar 25 17:52:24 2021 +0000

    Re-work fix for complete()/dispatch() when in READ_WRITE state
    
    Previous fix only addressed dispatch. Mirror changes to complete().
    The *_PENDING states are only required if the complete()/dispatch() is
    performed on a non-container thread. If on a container thread the race
    condition cannot occur.
---
 java/org/apache/coyote/AsyncStateMachine.java | 37 +++++++++++++++------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/java/org/apache/coyote/AsyncStateMachine.java b/java/org/apache/coyote/AsyncStateMachine.java
index 4cc194e..3176246 100644
--- a/java/org/apache/coyote/AsyncStateMachine.java
+++ b/java/org/apache/coyote/AsyncStateMachine.java
@@ -91,19 +91,23 @@ import org.apache.tomcat.util.security.PrivilegedSetTccl;
  *    |                                   /  |  \                                     |
  *    |                    OT-complete() /   |   \    OT-dispatch()                   |
  *    |   COMPLETE_PENDING«------«------/    |    \-------»---------»DISPATCH_PENDING |
- *    |          |    /|\                    |                       /|\ |            |
- *    |          |     |                     |                        |  |post()      |
- *    |          |     |complete()           |              dispatch()|  |            |
- *    |          |     |                     |                        |  |            |
- *    |          |     |---------«-------«-- | --«---READ_WRITE--»----|  |            |
- *    |          |                           |        /  /|\             |            |
- *    |          |                           | post()/   /               |            |
- *    |          |                           |      /   /                |            |
- *    |          |                           |     /   /                 |            |
- *    |          |                           |    /   /                  |            |
- *    |    post()|   timeout()         post()|   /   /asyncOperation()   |  timeout() |
- *    |          |   |--|                    |   |  /                    |    |--|    |
- *    |         \|/ \|/ |   complete()      \|/ \|//   dispatch()       \|/  \|/ |    |
+ *    |        |      /|\                    |                       /|\ |            |
+ *    |        |       |                     |                        |  |post()      |
+ *    |        |       |OT-complete()        |           OT-dispatch()|  |            |
+ *    |        |       |---------«-------«---|---«--\                 |  |            |
+ *    |        |                             |       \                |  |            |
+ *    |        |         /-------«-------«-- | --«---READ_WRITE--»----|  |            |
+ *    |        |        / ST-complete()      |        /  /|\  \          |            |
+ *    |        |       /                     | post()/   /     \         |            |
+ *    |        |      /                      |      /   /       \        |            |
+ *    |        |     /                       |     /   /         \       |            |
+ *    |        |    /                        |    /   /           \      |            |
+ *    |        |   /                         |   |   /             \     |            |
+ *    |        |  /                          |   |  /  ST-dispatch()\    |            |
+ *    |        |  |                          |   | |                 \   |            |
+ *    |  post()|  |  timeout()         post()|   | |asyncOperation()  \  |  timeout() |
+ *    |        |  |  |--|                    |   | |                  |  |    |--|    |
+ *    |       \|/\|/\|/ |     complete()    \|/ \|/|   dispatch()    \|/\|/  \|/ |    |
  *    |--«-----COMPLETING«--------«----------STARTED--------»---------»DISPATCHING----|
  *            /|\  /|\                       | /|\ |                       /|\ /|\
  *             |    |                        |  |--|                        |   |
@@ -301,7 +305,8 @@ class AsyncStateMachine {
 
 
     synchronized boolean asyncComplete() {
-        if (!ContainerThreadMarker.isContainerThread() && state == AsyncState.STARTING) {
+        if (!ContainerThreadMarker.isContainerThread() &&
+                (state == AsyncState.STARTING || state == AsyncState.READ_WRITE_OP)) {
             updateState(AsyncState.COMPLETE_PENDING);
             return false;
         }
@@ -362,8 +367,8 @@ class AsyncStateMachine {
 
 
     synchronized boolean asyncDispatch() {
-        if (!ContainerThreadMarker.isContainerThread() && state == AsyncState.STARTING ||
-                state == AsyncState.READ_WRITE_OP) {
+        if (!ContainerThreadMarker.isContainerThread() &&
+                (state == AsyncState.STARTING || state == AsyncState.READ_WRITE_OP)) {
             updateState(AsyncState.DISPATCH_PENDING);
             return false;
         }

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