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/24 19:04:29 UTC

[tomcat] branch 9.0.x updated (24c8ef1 -> 5d46443)

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

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


    from 24c8ef1  Re-order for more predictable behaviour
     new f16bd0e  Add some debug logging to the AsyncStateMachine
     new 5d46443  Enable debug logging for a test that is failing intermittently in CI

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 java/org/apache/coyote/AsyncStateMachine.java      | 56 ++++++++++++----------
 java/org/apache/coyote/LocalStrings.properties     |  1 +
 .../apache/catalina/core/TestAsyncContextImpl.java | 39 ++++++++-------
 3 files changed, 56 insertions(+), 40 deletions(-)

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


[tomcat] 02/02: Enable debug logging for a test that is failing intermittently in CI

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5d46443abcdf283c073247b22ca2cf6ce58cd697
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Mar 24 19:03:10 2021 +0000

    Enable debug logging for a test that is failing intermittently in CI
---
 .../apache/catalina/core/TestAsyncContextImpl.java | 39 +++++++++++++---------
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/test/org/apache/catalina/core/TestAsyncContextImpl.java b/test/org/apache/catalina/core/TestAsyncContextImpl.java
index e1672d3..b7de45d 100644
--- a/test/org/apache/catalina/core/TestAsyncContextImpl.java
+++ b/test/org/apache/catalina/core/TestAsyncContextImpl.java
@@ -28,6 +28,8 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Level;
+import java.util.logging.LogManager;
 
 import javax.servlet.AsyncContext;
 import javax.servlet.AsyncEvent;
@@ -2739,29 +2741,34 @@ public class TestAsyncContextImpl extends TomcatBaseTest {
 
 
     private void doTestAsyncIoEnd(boolean useThread, boolean useComplete) throws Exception {
-        Tomcat tomcat = getTomcatInstance();
+        LogManager.getLogManager().getLogger("org.apache.coyote").setLevel(Level.ALL);
+        try {
+            Tomcat tomcat = getTomcatInstance();
 
-        // No file system docBase required
-        Context ctx = tomcat.addContext("", null);
+            // No file system docBase required
+            Context ctx = tomcat.addContext("", null);
 
-        AsyncIoEndServlet asyncIoEndServlet = new AsyncIoEndServlet(useThread, useComplete);
-        Wrapper wrapper = Tomcat.addServlet(ctx, "asyncIoEndServlet", asyncIoEndServlet);
-        wrapper.setAsyncSupported(true);
-        ctx.addServletMappingDecoded("/asyncIoEndServlet", "asyncIoEndServlet");
+            AsyncIoEndServlet asyncIoEndServlet = new AsyncIoEndServlet(useThread, useComplete);
+            Wrapper wrapper = Tomcat.addServlet(ctx, "asyncIoEndServlet", asyncIoEndServlet);
+            wrapper.setAsyncSupported(true);
+            ctx.addServletMappingDecoded("/asyncIoEndServlet", "asyncIoEndServlet");
 
-        SimpleServlet simpleServlet = new SimpleServlet();
-        Tomcat.addServlet(ctx, "simpleServlet", simpleServlet);
-        ctx.addServletMappingDecoded("/simpleServlet", "simpleServlet");
+            SimpleServlet simpleServlet = new SimpleServlet();
+            Tomcat.addServlet(ctx, "simpleServlet", simpleServlet);
+            ctx.addServletMappingDecoded("/simpleServlet", "simpleServlet");
 
-        tomcat.start();
+            tomcat.start();
 
-        ByteChunk body = new ByteChunk();
-        int rc = getUrl("http://localhost:" + getPort() + "/asyncIoEndServlet", body, null);
+            ByteChunk body = new ByteChunk();
+            int rc = getUrl("http://localhost:" + getPort() + "/asyncIoEndServlet", body, null);
 
-        Assert.assertEquals(HttpServletResponse.SC_OK, rc);
-        Assert.assertEquals("OK", body.toString());
+            Assert.assertEquals(HttpServletResponse.SC_OK, rc);
+            Assert.assertEquals("OK", body.toString());
 
-        Assert.assertFalse(asyncIoEndServlet.getInvalidStateDetected());
+            Assert.assertFalse(asyncIoEndServlet.getInvalidStateDetected());
+        } finally {
+            LogManager.getLogManager().getLogger("org.apache.coyote").setLevel(Level.INFO);
+        }
     }
 
 

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


[tomcat] 01/02: Add some debug logging to the AsyncStateMachine

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f16bd0e382eea552f00f924127e11145f5502db8
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Mar 24 19:02:36 2021 +0000

    Add some debug logging to the AsyncStateMachine
---
 java/org/apache/coyote/AsyncStateMachine.java  | 56 +++++++++++++++-----------
 java/org/apache/coyote/LocalStrings.properties |  1 +
 2 files changed, 33 insertions(+), 24 deletions(-)

diff --git a/java/org/apache/coyote/AsyncStateMachine.java b/java/org/apache/coyote/AsyncStateMachine.java
index a993a39..4ad5a0d 100644
--- a/java/org/apache/coyote/AsyncStateMachine.java
+++ b/java/org/apache/coyote/AsyncStateMachine.java
@@ -20,6 +20,8 @@ import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.concurrent.atomic.AtomicLong;
 
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState;
 import org.apache.tomcat.util.res.StringManager;
 import org.apache.tomcat.util.security.PrivilegedGetTccl;
@@ -120,9 +122,7 @@ import org.apache.tomcat.util.security.PrivilegedSetTccl;
  */
 class AsyncStateMachine {
 
-    /**
-     * The string manager for this package.
-     */
+    private static final Log log = LogFactory.getLog(AsyncStateMachine.class);
     private static final StringManager sm = StringManager.getManager(AsyncStateMachine.class);
 
     private enum AsyncState {
@@ -234,7 +234,7 @@ class AsyncStateMachine {
     synchronized void asyncStart(AsyncContextCallback asyncCtxt) {
         if (state == AsyncState.DISPATCHED) {
             generation.incrementAndGet();
-            state = AsyncState.STARTING;
+            updateState(AsyncState.STARTING);
             // Note: In this instance, caller is responsible for calling
             // asyncCtxt.incrementInProgressAsyncCount() as that allows simpler
             // error handling.
@@ -249,7 +249,7 @@ class AsyncStateMachine {
 
     synchronized void asyncOperation() {
         if (state==AsyncState.STARTED) {
-            state = AsyncState.READ_WRITE_OP;
+            updateState(AsyncState.READ_WRITE_OP);
         } else {
             throw new IllegalStateException(
                     sm.getString("asyncStateMachine.invalidAsyncState",
@@ -265,25 +265,25 @@ class AsyncStateMachine {
     synchronized SocketState asyncPostProcess() {
         if (state == AsyncState.COMPLETE_PENDING) {
             clearNonBlockingListeners();
-            state = AsyncState.COMPLETING;
+            updateState(AsyncState.COMPLETING);
             return SocketState.ASYNC_END;
         } else if (state == AsyncState.DISPATCH_PENDING) {
             clearNonBlockingListeners();
-            state = AsyncState.DISPATCHING;
+            updateState(AsyncState.DISPATCHING);
             return SocketState.ASYNC_END;
         } else  if (state == AsyncState.STARTING || state == AsyncState.READ_WRITE_OP) {
-            state = AsyncState.STARTED;
+            updateState(AsyncState.STARTED);
             return SocketState.LONG;
         } else if (state == AsyncState.MUST_COMPLETE || state == AsyncState.COMPLETING) {
             asyncCtxt.fireOnComplete();
-            state = AsyncState.DISPATCHED;
+            updateState(AsyncState.DISPATCHED);
             asyncCtxt.decrementInProgressAsyncCount();
             return SocketState.ASYNC_END;
         } else if (state == AsyncState.MUST_DISPATCH) {
-            state = AsyncState.DISPATCHING;
+            updateState(AsyncState.DISPATCHING);
             return SocketState.ASYNC_END;
         } else if (state == AsyncState.DISPATCHING) {
-            state = AsyncState.DISPATCHED;
+            updateState(AsyncState.DISPATCHED);
             asyncCtxt.decrementInProgressAsyncCount();
             return SocketState.ASYNC_END;
         } else if (state == AsyncState.STARTED) {
@@ -300,7 +300,7 @@ class AsyncStateMachine {
 
     synchronized boolean asyncComplete() {
         if (!ContainerThreadMarker.isContainerThread() && state == AsyncState.STARTING) {
-            state = AsyncState.COMPLETE_PENDING;
+            updateState(AsyncState.COMPLETE_PENDING);
             return false;
         }
 
@@ -309,9 +309,9 @@ class AsyncStateMachine {
         if (state == AsyncState.STARTING || state == AsyncState.MUST_ERROR) {
             // Processing is on a container thread so no need to transfer
             // processing to a new container thread
-            state = AsyncState.MUST_COMPLETE;
+            updateState(AsyncState.MUST_COMPLETE);
         } else if (state == AsyncState.STARTED) {
-            state = AsyncState.COMPLETING;
+            updateState(AsyncState.COMPLETING);
             // A dispatch to a container thread is always required.
             // If on a non-container thread, need to get back onto a container
             // thread to complete the processing.
@@ -331,7 +331,7 @@ class AsyncStateMachine {
             // 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.
-            state = AsyncState.COMPLETING;
+            updateState(AsyncState.COMPLETING);
         } else {
             throw new IllegalStateException(
                     sm.getString("asyncStateMachine.invalidAsyncState",
@@ -343,7 +343,7 @@ class AsyncStateMachine {
 
     synchronized boolean asyncTimeout() {
         if (state == AsyncState.STARTED) {
-            state = AsyncState.TIMING_OUT;
+            updateState(AsyncState.TIMING_OUT);
             return true;
         } else if (state == AsyncState.COMPLETING ||
                 state == AsyncState.DISPATCHING ||
@@ -361,7 +361,7 @@ class AsyncStateMachine {
 
     synchronized boolean asyncDispatch() {
         if (!ContainerThreadMarker.isContainerThread() && state == AsyncState.STARTING) {
-            state = AsyncState.DISPATCH_PENDING;
+            updateState(AsyncState.DISPATCH_PENDING);
             return false;
         }
 
@@ -370,9 +370,9 @@ class AsyncStateMachine {
         if (state == AsyncState.STARTING || state == AsyncState.MUST_ERROR) {
             // Processing is on a container thread so no need to transfer
             // processing to a new container thread
-            state = AsyncState.MUST_DISPATCH;
+            updateState(AsyncState.MUST_DISPATCH);
         } else if (state == AsyncState.STARTED) {
-            state = AsyncState.DISPATCHING;
+            updateState(AsyncState.DISPATCHING);
             // A dispatch to a container thread is always required.
             // If on a non-container thread, need to get back onto a container
             // thread to complete the processing.
@@ -392,7 +392,7 @@ class AsyncStateMachine {
             // 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.
-            state = AsyncState.DISPATCHING;
+            updateState(AsyncState.DISPATCHING);
         } else {
             throw new IllegalStateException(
                     sm.getString("asyncStateMachine.invalidAsyncState",
@@ -405,7 +405,7 @@ class AsyncStateMachine {
     synchronized void asyncDispatched() {
         if (state == AsyncState.DISPATCHING ||
                 state == AsyncState.MUST_DISPATCH) {
-            state = AsyncState.DISPATCHED;
+            updateState(AsyncState.DISPATCHED);
             asyncCtxt.decrementInProgressAsyncCount();
         } else {
             throw new IllegalStateException(
@@ -418,15 +418,15 @@ class AsyncStateMachine {
     synchronized boolean asyncError() {
         clearNonBlockingListeners();
         if (state == AsyncState.STARTING) {
-            state = AsyncState.MUST_ERROR;
+            updateState(AsyncState.MUST_ERROR);
         } else if (state == AsyncState.DISPATCHED) {
             // Async error handling has moved processing back into an async
             // state. Need to increment in progress count as it will decrement
             // when the async state is exited again.
             asyncCtxt.incrementInProgressAsyncCount();
-            state = AsyncState.ERROR;
+            updateState(AsyncState.ERROR);
         } else {
-            state = AsyncState.ERROR;
+            updateState(AsyncState.ERROR);
         }
         return !ContainerThreadMarker.isContainerThread();
     }
@@ -503,4 +503,12 @@ class AsyncStateMachine {
         processor.getRequest().listener = null;
         processor.getRequest().getResponse().listener = null;
     }
+
+
+    private synchronized void updateState(AsyncState newState) {
+        if (log.isDebugEnabled()) {
+            log.debug(sm.getString("asyncStateMachine.stateChange", state, newState));
+        }
+        state = newState;
+    }
 }
diff --git a/java/org/apache/coyote/LocalStrings.properties b/java/org/apache/coyote/LocalStrings.properties
index 595cfb2..724a0e4 100644
--- a/java/org/apache/coyote/LocalStrings.properties
+++ b/java/org/apache/coyote/LocalStrings.properties
@@ -52,6 +52,7 @@ abstractProtocolHandler.start=Starting ProtocolHandler [{0}]
 abstractProtocolHandler.stop=Stopping ProtocolHandler [{0}]
 
 asyncStateMachine.invalidAsyncState=Calling [{0}] is not valid for a request with Async state [{1}]
+asyncStateMachine.stateChange=Changing async state from [{0}] to [{1}]
 
 compressionConfig.ContentEncodingParseFail=Failed to parse Content-Encoding header when checking to see if compression was already in use
 

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