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

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


The following commit(s) were added to refs/heads/10.0.x by this push:
     new acebbe0  Stop sendfile before closing sockets
acebbe0 is described below

commit acebbe073fb31bdd496940b8f9b3ef90dc68bf10
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue Nov 23 19:10:09 2021 +0000

    Stop sendfile before closing sockets
---
 java/org/apache/tomcat/util/net/AprEndpoint.java | 55 ++++++++++++------------
 1 file changed, 28 insertions(+), 27 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java 
b/java/org/apache/tomcat/util/net/AprEndpoint.java
index 578a571..04651a3 100644
--- a/java/org/apache/tomcat/util/net/AprEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AprEndpoint.java
@@ -580,6 +580,34 @@ public class AprEndpoint extends 
AbstractEndpoint<Long,Long> implements SNICallB
                 // Ignore
             }
 
+            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
+                }
+                sendfile = null;
+            }
+
             // Close the SocketWrapper for each open connection - this should
             // trigger a IOException when the app (or container) tries to 
write.
             // Use the blocking status write lock as a proxy for a lock on
@@ -609,33 +637,6 @@ public class AprEndpoint extends 
AbstractEndpoint<Long,Long> implements SNICallB
             }
             poller = null;
             connections.clear();
-            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
-                }
-                sendfile = null;
-            }
             if (processorCache != null) {
                 processorCache.clear();
                 processorCache = null;

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

Reply via email to