This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new 2bfbbef BZ65757: Fix forgotten test case 2bfbbef is described below commit 2bfbbef65d1b1b07da46c8dcd6cee96cb5567998 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 +--- webapps/docs/changelog.xml | 4 ++++ 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/java/org/apache/catalina/connector/CoyoteAdapter.java b/java/org/apache/catalina/connector/CoyoteAdapter.java index 766c11f..d9714e0 100644 --- a/java/org/apache/catalina/connector/CoyoteAdapter.java +++ b/java/org/apache/catalina/connector/CoyoteAdapter.java @@ -140,6 +140,7 @@ public class CoyoteAdapter implements Adapter { AsyncContextImpl asyncConImpl = request.getAsyncContextInternal(); req.getRequestProcessor().setWorkerThreadName(THREAD_NAME.get()); + req.setRequestThread(); try { if (!request.isAsync()) { @@ -351,6 +352,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 1fbc3a9..5423517 100644 --- a/java/org/apache/catalina/connector/InputBuffer.java +++ b/java/org/apache/catalina/connector/InputBuffer.java @@ -32,7 +32,6 @@ import javax.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; @@ -274,7 +273,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 b82856d..677f113 100644 --- a/java/org/apache/coyote/Request.java +++ b/java/org/apache/coyote/Request.java @@ -154,6 +154,7 @@ public final class Request { private long bytesRead=0; // Time of the request - useful to avoid repeated calls to System.currentTime private long startTime = -1; + private long threadId = 0; private int available = 0; private final RequestInfo reqProcessorMX=new RequestInfo(this); @@ -220,7 +221,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); } @@ -717,6 +718,18 @@ public final class Request { this.startTime = startTime; } + public long getThreadId() { + return threadId; + } + + public void setRequestThread() { + threadId = Thread.currentThread().getId(); + } + + public boolean isRequestThread() { + return Thread.currentThread().getId() == threadId; + } + // -------------------- Per-Request "notes" -------------------- @@ -799,6 +812,7 @@ public final class Request { allDataReadEventSent.set(false); startTime = -1; + threadId = 0; } // -------------------- Info -------------------- diff --git a/java/org/apache/coyote/Response.java b/java/org/apache/coyote/Response.java index d25d570..f3bcd8b 100644 --- a/java/org/apache/coyote/Response.java +++ b/java/org/apache/coyote/Response.java @@ -725,7 +725,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 4acf073..a7740ef 100644 --- a/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java +++ b/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java @@ -51,7 +51,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import org.apache.catalina.Context; @@ -928,7 +927,6 @@ public class TestNonBlockingAPI extends TomcatBaseTest { } - @Ignore @Test public void testDelayedNBWrite() throws Exception { Tomcat tomcat = getTomcatInstance(); @@ -978,7 +976,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(); diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 911fd24..433fad9 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -185,6 +185,10 @@ Restore pre-starting of <code>minSpareThreads</code> lost in the fix for <bug>65454</bug>. (markt) </fix> + <fix> + <bug>65757</bug>: Missing initial IO listener notification on Servlet + container dispatch to another container thread. (remm) + </fix> </changelog> </subsection> <subsection name="Jasper"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org