This is an automated email from the ASF dual-hosted git repository. rmaucher pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 6fef7d01ad7695ff9d7c0ade90bd0b3071e46f0b 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 7a95ab3ff1..9a2752c042 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 @@ -880,18 +880,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]
