This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new 72db699456 Preparatory work for APR/Native shutdown stability fix 72db699456 is described below commit 72db699456ef24d2cc50e9020634a628452bdcfb Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Feb 8 18:47:07 2024 +0000 Preparatory work for APR/Native shutdown stability fix --- .../apache/catalina/core/AprLifecycleListener.java | 1 + java/org/apache/tomcat/jni/Library.java | 32 ++++++++++++++++++---- test/org/apache/tomcat/util/net/TesterSupport.java | 1 + 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/java/org/apache/catalina/core/AprLifecycleListener.java b/java/org/apache/catalina/core/AprLifecycleListener.java index 8a6184438d..4ed37531fa 100644 --- a/java/org/apache/catalina/core/AprLifecycleListener.java +++ b/java/org/apache/catalina/core/AprLifecycleListener.java @@ -169,6 +169,7 @@ public class AprLifecycleListener implements LifecycleListener { } private static void terminateAPR() { + Library.terminatePrepare(); Library.terminate(); AprStatus.setAprAvailable(false); AprStatus.setAprInitialized(false); diff --git a/java/org/apache/tomcat/jni/Library.java b/java/org/apache/tomcat/jni/Library.java index c0256eacff..8354406450 100644 --- a/java/org/apache/tomcat/jni/Library.java +++ b/java/org/apache/tomcat/jni/Library.java @@ -29,6 +29,8 @@ public final class Library { */ private static Library _instance = null; + private static boolean initialized = false; + private Library() throws Exception { boolean loaded = false; StringBuilder err = new StringBuilder(); @@ -97,12 +99,26 @@ public final class Library { System.loadLibrary(libraryName); } - /* create global TCN's APR pool - * This has to be the first call to TCN library. + /** + * Create Tomcat Native's global APR pool. This has to be the first call to TCN library. */ private static native boolean initialize(); - /* destroy global TCN's APR pool - * This has to be the last call to TCN library. + /** + * Signal that Tomcat Native is about to be shutdown. + * <p> + * The main purpose of this flag is to allow instances that manage their own APR root pools to determine if those + * pools need to be explicitly cleaned up or if they will be / have been cleaned up by the call to + * {@link #terminate()}. The code needs to avoid multiple attempts to clean up these pools else the Native code may + * crash. + */ + public static void terminatePrepare() { + initialized = false; + } + /** + * Destroys Tomcat Native's global APR pool. This has to be the last call to TCN library. This will destroy any APR + * root pools that have not been explicitly destroyed. + * <p> + * Callers of this method should call {@link #terminatePrepare()} before calling this method. */ public static native void terminate(); /* Internal function for loading APR Features */ @@ -161,6 +177,12 @@ public final class Library { aprVersionString() + ")"); } } - return initialize(); + initialized = initialize(); + return initialized; + } + + + public static boolean isInitialized() { + return initialized; } } diff --git a/test/org/apache/tomcat/util/net/TesterSupport.java b/test/org/apache/tomcat/util/net/TesterSupport.java index 5d56e49989..a9b32fdc50 100644 --- a/test/org/apache/tomcat/util/net/TesterSupport.java +++ b/test/org/apache/tomcat/util/net/TesterSupport.java @@ -108,6 +108,7 @@ public final class TesterSupport { Library.initialize(null); available = true; version = SSL.version(); + Library.terminatePrepare(); Library.terminate(); } catch (Exception | LibraryNotFoundError ex) { err = ex.getMessage(); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org