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:37:37 UTC

[tomcat] branch 8.5.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 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 396353c  Fix timeout on zero length read/write with useAsyncIO for NIO and APR
396353c is described below

commit 396353c9d0eeb8648009023525f2605b9d04ee83
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 64f0257..9849417 100644
--- a/java/org/apache/tomcat/util/net/AprEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AprEndpoint.java
@@ -2690,6 +2690,7 @@ public class AprEndpoint extends AbstractEndpoint<Long> implements SNICallBack {
                             }
                             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 ddf9d5e..d17adc0 100644
--- a/java/org/apache/tomcat/util/net/Nio2Endpoint.java
+++ b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
@@ -684,15 +684,6 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel> {
 
         }
 
-        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 bfac6d7..fe6f65f 100644
--- a/java/org/apache/tomcat/util/net/NioEndpoint.java
+++ b/java/org/apache/tomcat/util/net/NioEndpoint.java
@@ -1532,7 +1532,7 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel> {
                                     updateLastWrite();
                                 }
                             }
-                            if (nBytes != 0) {
+                            if (nBytes != 0 || !arrayHasData(buffers)) {
                                 completionDone = false;
                             }
                         }
@@ -1540,7 +1540,7 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel> {
                         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 adeba23..3a859e7 100644
--- a/java/org/apache/tomcat/util/net/SocketWrapperBase.java
+++ b/java/org/apache/tomcat/util/net/SocketWrapperBase.java
@@ -1425,4 +1425,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 cb71df5..ff7946c 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -72,6 +72,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