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 2021/11/09 17:27:54 UTC

[tomcat] branch 9.0.x updated: Move the wait for the sendfile thread to exit. Align with Poller thread

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 dcc9133  Move the wait for the sendfile thread to exit. Align with Poller thread
dcc9133 is described below

commit dcc913333b0649a8ffe2cd11fbb1f5e5b260d94b
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue Nov 9 17:26:59 2021 +0000

    Move the wait for the sendfile thread to exit. Align with Poller thread
    
    The code can't wait for the snedfile thread to stop in sendfile.stop as
    that is in a sync block and the snedfile thread won't exit the wait
    until the thead calling stop exists and releases the sync.
---
 java/org/apache/tomcat/util/net/AprEndpoint.java | 34 +++++++++++++-----------
 webapps/docs/changelog.xml                       |  4 +++
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java b/java/org/apache/tomcat/util/net/AprEndpoint.java
index 725195a..c97e3e1 100644
--- a/java/org/apache/tomcat/util/net/AprEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AprEndpoint.java
@@ -607,6 +607,24 @@ public class AprEndpoint extends AbstractEndpoint<Long,Long> implements SNICallB
             if (getUseSendfile()) {
                 try {
                     sendfile.stop();
+
+                    // Wait for the sendfile thread to exit, otherwise parallel
+                    // destruction of sockets which are still in the poller can cause
+                    // problems.
+                    waitMillis = 0;
+                    try {
+                        while (sendfile.sendfileThread.isAlive() && waitMillis < 10000) {
+                            waitMillis++;
+                            Thread.sleep(1);
+                        }
+                    } catch (InterruptedException e) {
+                        // Ignore
+                    }
+
+                    if (sendfile.sendfileThread.isAlive()) {
+                        log.warn(sm.getString("endpoint.sendfileThreadStop"));
+                    }
+
                     sendfile.destroy();
                 } catch (Exception e) {
                     // Ignore
@@ -1723,22 +1741,6 @@ public class AprEndpoint extends AbstractEndpoint<Long,Long> implements SNICallB
             sendfileRunning = false;
             // In case the sendfile thread is in the idle wait
             this.notify();
-
-            // Wait for the sendfile thread to exit, otherwise parallel
-            // destruction of sockets which are still in the poller can cause
-            // problems.
-            int loops = 50;
-            while (loops > 0 && sendfileThread.isAlive()) {
-                try {
-                    this.wait(pollTime / 1000);
-                } catch (InterruptedException e) {
-                    // Ignore
-                }
-                loops--;
-            }
-            if (sendfileThread.isAlive()) {
-                log.warn(sm.getString("endpoint.sendfileThreadStop"));
-            }
         }
 
         /**
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index cf41f56..bdde649 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -147,6 +147,10 @@
         tomcat-native or APR. Please refer to the <code>openssl-java17</code>
         module from the <code>main</code> branch for more details. (remm)
       </add>
+      <fix>
+        Fix APR connector stop so it correctly waits for the sendfile thread, if
+        any, to exit. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">

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