Hmm.

This patch shouldn't have been necessary.

It appeared to fix the issue in the IDE but it didn't fix it on the command line. I'm probably going to revert this fix but before I do I want to dig deeper. Something odd is going on...

Mark


On 30/10/2025 18:05, [email protected] wrote:
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 f3b7bdc301 Fix consistent crash (on Unix with OpenSSL provider) in 
tests
f3b7bdc301 is described below

commit f3b7bdc30176acc6fd5a98c075fedf60232454b2
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Oct 30 18:05:18 2025 +0000

     Fix consistent crash (on Unix with OpenSSL provider) in tests
---
  .../tomcat/util/net/openssl/OpenSSLContext.java    | 32 +++++++++++++++++-----
  1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/openssl/OpenSSLContext.java 
b/java/org/apache/tomcat/util/net/openssl/OpenSSLContext.java
index 65dd146396..15a734470a 100644
--- a/java/org/apache/tomcat/util/net/openssl/OpenSSLContext.java
+++ b/java/org/apache/tomcat/util/net/openssl/OpenSSLContext.java
@@ -584,22 +584,40 @@ public class OpenSSLContext implements 
org.apache.tomcat.util.net.SSLContext {
      }
- /**
-     * @param aprPool the APR pool
-     * @param cctx    OpenSSLConfCmd context
-     * @param ctx     SSL context
-     */
-    private record OpenSSLState(long aprPool, long cctx, long ctx) implements 
Runnable {
+    private class OpenSSLState implements Runnable {
+        private volatile long aprPool;
+        private volatile long cctx;
+        private volatile long ctx;
+
+        /**
+         * @param aprPool the APR pool
+         * @param cctx    OpenSSLConfCmd context
+         * @param ctx     SSL context
+         */
+        OpenSSLState(long aprPool, long cctx, long ctx) {
+            this.aprPool = aprPool;
+            this.cctx = cctx;
+            this.ctx = ctx;
+        }
+
+        /*
+         * This runnable can be called by the cleaner thread during GC but 
also by OpenSSLContext.destroy() so we need
+         * to make sure that the free() methods are only called once. Calling 
them more than once will trigger a JVM
+         * crash.
+         */
          @Override
-        public void run() {
+        public synchronized void run() {
              if (ctx != 0) {
                  SSLContext.free(ctx);
+                ctx = 0;
              }
              if (cctx != 0) {
                  SSLConf.free(cctx);
+                cctx = 0;
              }
              if (aprPool != 0) {
                  Pool.destroy(aprPool);
+                aprPool = 0;
              }
          }
      }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to