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 2020/02/12 17:36:58 UTC

[tomcat] branch 9.0.x updated: Fix timeout on zero length read/write with useAsyncIO for NIO and APR

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


The following commit(s) were added to refs/heads/9.0.x by this push:
     new d779026  Fix timeout on zero length read/write with useAsyncIO for NIO and APR
d779026 is described below

commit d779026837238cb320dbfdb3e6bd6d78fdc793fb
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Feb 12 17:27:25 2020 +0000

    Fix timeout on zero length read/write with useAsyncIO for NIO and APR
---
 java/org/apache/tomcat/util/net/AprEndpoint.java       |  1 +
 java/org/apache/tomcat/util/net/Nio2Endpoint.java      |  9 ---------
 java/org/apache/tomcat/util/net/NioEndpoint.java       |  4 ++--
 java/org/apache/tomcat/util/net/SocketWrapperBase.java |  9 +++++++++
 webapps/docs/changelog.xml                             | 10 ++++++++++
 5 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java b/java/org/apache/tomcat/util/net/AprEndpoint.java
index b8b71e3..ec9deee 100644
--- a/java/org/apache/tomcat/util/net/AprEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AprEndpoint.java
@@ -2646,6 +2646,7 @@ public class AprEndpoint extends AbstractEndpoint<Long,Long> implements SNICallB
                             }
                             if (buffer == null && flushBytes == 0) {
                                 // Nothing to do
+                                completion.completed(Long.valueOf(0), this);
                                 return;
                             }
                             if (read) {
diff --git a/java/org/apache/tomcat/util/net/Nio2Endpoint.java b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
index adafdad..67d0b81 100644
--- a/java/org/apache/tomcat/util/net/Nio2Endpoint.java
+++ b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
@@ -726,15 +726,6 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS
 
         }
 
-        private static boolean arrayHasData(ByteBuffer[] byteBuffers) {
-            for (ByteBuffer byteBuffer : byteBuffers) {
-                if (byteBuffer.hasRemaining()) {
-                    return true;
-                }
-            }
-            return false;
-        }
-
 
         public void setSendfileData(SendfileData sf) { this.sendfileData = sf; }
         public SendfileData getSendfileData() { return this.sendfileData; }
diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java
index 9a70075..af17c3b 100644
--- a/java/org/apache/tomcat/util/net/NioEndpoint.java
+++ b/java/org/apache/tomcat/util/net/NioEndpoint.java
@@ -1543,7 +1543,7 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel>
                                     updateLastWrite();
                                 }
                             }
-                            if (nBytes != 0) {
+                            if (nBytes != 0 || !arrayHasData(buffers)) {
                                 completionDone = false;
                             }
                         }
@@ -1551,7 +1551,7 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel>
                         setError(e);
                     }
                 }
-                if (nBytes > 0) {
+                if (nBytes > 0 || (nBytes == 0 && !arrayHasData(buffers))) {
                     // The bytes processed are only updated in the completion handler
                     completion.completed(Long.valueOf(nBytes), this);
                 } else if (nBytes < 0 || getError() != null) {
diff --git a/java/org/apache/tomcat/util/net/SocketWrapperBase.java b/java/org/apache/tomcat/util/net/SocketWrapperBase.java
index f205725..383d96c 100644
--- a/java/org/apache/tomcat/util/net/SocketWrapperBase.java
+++ b/java/org/apache/tomcat/util/net/SocketWrapperBase.java
@@ -1474,4 +1474,13 @@ public abstract class SocketWrapperBase<E> {
         }
         return max;
     }
+
+    protected static boolean arrayHasData(ByteBuffer[] byteBuffers) {
+        for (ByteBuffer byteBuffer : byteBuffers) {
+            if (byteBuffer.hasRemaining()) {
+                return true;
+            }
+        }
+        return false;
+    }
 }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 0906b88..18dede0 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -66,6 +66,16 @@
       </fix>
     </changelog>
   </subsection>
+  <subsection name="Coyote">
+    <changelog>
+      <fix>
+        When the NIO or APR/native connectors were configured with
+        <code>useAsyncIO="true"</code> and a zero length read or write was
+        performed, the read/write would time out rather than return immediately.
+        (markt)
+      </fix>
+    </changelog>
+  </subsection>
   <subsection name="Jasper">
     <changelog>
       <scode>


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