This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 10.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.0.x by this push: new 2269c82 BZ65757: Fix forgotten test case 2269c82 is described below commit 2269c8243eb971cd33ea1af1adf3904aaf9f1803 Author: remm <r...@apache.org> AuthorDate: Mon Jan 3 16:05:22 2022 +0100 BZ65757: Fix forgotten test case Dispaching in the servlet container when using non blocking IO needs better thread identification. Otherwise, the container could see a container thread and believe it doesn't need an explicit notification, while actually the thread was simply running another request (so no async post process). --- java/org/apache/catalina/connector/CoyoteAdapter.java | 2 ++ java/org/apache/catalina/connector/InputBuffer.java | 3 +-- java/org/apache/coyote/Request.java | 16 +++++++++++++++- java/org/apache/coyote/Response.java | 2 +- .../apache/catalina/nonblocking/TestNonBlockingAPI.java | 4 +--- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/java/org/apache/catalina/connector/CoyoteAdapter.java b/java/org/apache/catalina/connector/CoyoteAdapter.java index ea3dbe4..3d9b52e 100644 --- a/java/org/apache/catalina/connector/CoyoteAdapter.java +++ b/java/org/apache/catalina/connector/CoyoteAdapter.java @@ -129,6 +129,7 @@ public class CoyoteAdapter implements Adapter { AsyncContextImpl asyncConImpl = request.getAsyncContextInternal(); req.getRequestProcessor().setWorkerThreadName(THREAD_NAME.get()); + req.setRequestThread(); try { if (!request.isAsync()) { @@ -340,6 +341,7 @@ public class CoyoteAdapter implements Adapter { boolean postParseSuccess = false; req.getRequestProcessor().setWorkerThreadName(THREAD_NAME.get()); + req.setRequestThread(); try { // Parse and set Catalina and configuration specific diff --git a/java/org/apache/catalina/connector/InputBuffer.java b/java/org/apache/catalina/connector/InputBuffer.java index de306f5..ac1b816 100644 --- a/java/org/apache/catalina/connector/InputBuffer.java +++ b/java/org/apache/catalina/connector/InputBuffer.java @@ -32,7 +32,6 @@ import jakarta.servlet.ReadListener; import org.apache.catalina.security.SecurityUtil; import org.apache.coyote.ActionCode; -import org.apache.coyote.ContainerThreadMarker; import org.apache.coyote.Request; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; @@ -266,7 +265,7 @@ public class InputBuffer extends Reader // If this is a non-container thread, need to trigger a read // which will eventually lead to a call to onAllDataRead() via a // container thread. - if (!ContainerThreadMarker.isContainerThread()) { + if (!coyoteRequest.isRequestThread()) { coyoteRequest.action(ActionCode.DISPATCH_READ, null); coyoteRequest.action(ActionCode.DISPATCH_EXECUTE, null); } diff --git a/java/org/apache/coyote/Request.java b/java/org/apache/coyote/Request.java index 157a989..c798199 100644 --- a/java/org/apache/coyote/Request.java +++ b/java/org/apache/coyote/Request.java @@ -155,6 +155,7 @@ public final class Request { private long bytesRead=0; // Time of the request - useful to avoid repeated calls to System.currentTime private long startTimeNanos = -1; + private long threadId = 0; private int available = 0; private final RequestInfo reqProcessorMX=new RequestInfo(this); @@ -221,7 +222,7 @@ public final class Request { fireListener = true; } action(ActionCode.DISPATCH_READ, null); - if (!ContainerThreadMarker.isContainerThread()) { + if (!isRequestThread()) { // Not on a container thread so need to execute the dispatch action(ActionCode.DISPATCH_EXECUTE, null); } @@ -701,6 +702,18 @@ public final class Request { this.startTimeNanos = startTimeNanos; } + public long getThreadId() { + return threadId; + } + + public void setRequestThread() { + threadId = Thread.currentThread().getId(); + } + + public boolean isRequestThread() { + return Thread.currentThread().getId() == threadId; + } + // -------------------- Per-Request "notes" -------------------- @@ -784,6 +797,7 @@ public final class Request { allDataReadEventSent.set(false); startTimeNanos = -1; + threadId = 0; } // -------------------- Info -------------------- diff --git a/java/org/apache/coyote/Response.java b/java/org/apache/coyote/Response.java index 604415a..388ac64 100644 --- a/java/org/apache/coyote/Response.java +++ b/java/org/apache/coyote/Response.java @@ -737,7 +737,7 @@ public final class Response { fireListener = true; } action(ActionCode.DISPATCH_WRITE, null); - if (!ContainerThreadMarker.isContainerThread()) { + if (!req.isRequestThread()) { // Not on a container thread so need to execute the dispatch action(ActionCode.DISPATCH_EXECUTE, null); } diff --git a/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java b/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java index a9d631c..9c5f524 100644 --- a/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java +++ b/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java @@ -52,7 +52,6 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import org.apache.catalina.Context; @@ -929,7 +928,6 @@ public class TestNonBlockingAPI extends TomcatBaseTest { } - @Ignore @Test public void testDelayedNBWrite() throws Exception { Tomcat tomcat = getTomcatInstance(); @@ -979,7 +977,7 @@ public class TestNonBlockingAPI extends TomcatBaseTest { try { ByteChunk result = new ByteChunk(); int rc = getUrl(url, result, null); - Assert.assertTrue(rc == HttpServletResponse.SC_OK); + Assert.assertEquals(HttpServletResponse.SC_OK, rc); Assert.assertTrue(result.toString().contains("OK")); } catch (Throwable e) { e.printStackTrace(); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org