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 843c693 Move the wait for the sendfile thread to exit. Align with Poller thread 843c693 is described below commit 843c693d110ef6ae44c2930357200bc90e8c42ba 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 4f44e62..2b60bf4 100644 --- a/java/org/apache/tomcat/util/net/AprEndpoint.java +++ b/java/org/apache/tomcat/util/net/AprEndpoint.java @@ -611,6 +611,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 @@ -1727,22 +1745,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 9f57152..3342007 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-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org