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

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


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 915c2d9  BZ65757: Fix forgotten test case
915c2d9 is described below

commit 915c2d97cf366300d8a7175b6ec529426029f83e
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 71ff866..2e8a4d5 100644
--- a/java/org/apache/catalina/connector/CoyoteAdapter.java
+++ b/java/org/apache/catalina/connector/CoyoteAdapter.java
@@ -133,6 +133,7 @@ public class CoyoteAdapter implements Adapter {
         AsyncContextImpl asyncConImpl = request.getAsyncContextInternal();
 
         req.getRequestProcessor().setWorkerThreadName(THREAD_NAME.get());
+        req.setRequestThread();
 
         try {
             if (!request.isAsync()) {
@@ -344,6 +345,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 a69effd..2488bd6 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;
@@ -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 328cb03..a07d485 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);
             }
@@ -687,6 +688,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" --------------------
 
 
@@ -770,6 +783,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 26870ef..be187ec 100644
--- a/java/org/apache/coyote/Response.java
+++ b/java/org/apache/coyote/Response.java
@@ -727,7 +727,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 c26e1f0..dc1f580 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 e1e973d..810b019 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -128,6 +128,10 @@
         Revert the previous fix for <bug>65714</bug> and implement a more
         comprehensive fix. (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

Reply via email to