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

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

commit 9b124d72c3e01585485a66e695601b142c8d1aaa
Author: opencode <[email protected]>
AuthorDate: Tue Dec 1 21:43:59 2026 +0100

    Read interceptor start state under the start lock
    
    ConnectionPool.close read initializing, startedInterceptors, and 
startedInterceptorCount before acquiring interceptorStartLock. A close that 
observed the count from before a start callback it then waited for could use 
the stale prefix and skip that callback's poolClosed notification.
    
    Read the start state inside the lock, so the close sees the count written 
by any callback it waits for. mvn test passes: 1183 tests, 0 failures.
---
 .../apache/tomcat/jdbc/pool/ConnectionPool.java    | 25 ++++++++++++----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
index 627db21ac7..eeb4782ad2 100644
--- 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
+++ 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
@@ -875,18 +875,21 @@ public class ConnectionPool {
         // not register state that this close has already been delivered past.
         // The same monitor serializes the start callbacks, so an external 
close
         // waits for a running callback and no new start can slip in 
afterwards.
-        boolean closingDuringInit = initializing;
-        PoolProperties.InterceptorDefinition[] started = startedInterceptors;
-        int startedLimit = started == null ? 0
-                : (closingDuringInit ? Math.min(startedInterceptorCount, 
started.length) : started.length);
-        // The definitions actually told during a close that interrupted the
-        // start are only the prefix of startedInterceptors, not the complete
-        // parsed array: later entries have not run and must not suppress the
-        // notification of a chain definition that happened to use the same
-        // configuration.
-        PoolProperties.InterceptorDefinition[] toldStarted = closingDuringInit 
&& started != null
-                ? Arrays.copyOf(started, startedLimit) : started;
+        // Read the start state under the monitor as well: taking the count
+        // outside it can observe the value from before the callback the close
+        // then waits for, leaving that callback's definition unnotified.
         synchronized (interceptorStartLock) {
+            boolean closingDuringInit = initializing;
+            PoolProperties.InterceptorDefinition[] started = 
startedInterceptors;
+            int startedLimit = started == null ? 0
+                    : (closingDuringInit ? Math.min(startedInterceptorCount, 
started.length) : started.length);
+            // The definitions actually told during a close that interrupted 
the
+            // start are only the prefix of startedInterceptors, not the 
complete
+            // parsed array: later entries have not run and must not suppress 
the
+            // notification of a chain definition that happened to use the same
+            // configuration.
+            PoolProperties.InterceptorDefinition[] toldStarted = 
closingDuringInit && started != null
+                    ? Arrays.copyOf(started, startedLimit) : started;
             // No NPE. If started is null, startedLimit will be zero.
             for (int i = 0; i < startedLimit; i++) {
                 informInterceptorOfPoolClosure(started[i]);


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

Reply via email to