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 164bf394dd6076f61c62809c0c535c445a3f348f
Author: opencode <[email protected]>
AuthorDate: Wed Sep 30 22:56:03 2026 +0200

    Synchronize FileMessageFactory.isValid() with the write path and remove 
expired factories by instance to avoid racing with in-flight transfers
---
 java/org/apache/catalina/ha/deploy/FarmWarDeployer.java    | 6 ++++--
 java/org/apache/catalina/ha/deploy/FileMessageFactory.java | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java 
b/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
index f05013579b..1c9b9a4d60 100644
--- a/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
+++ b/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
@@ -838,8 +838,10 @@ public class FarmWarDeployer extends ClusterListener 
implements ClusterDeployer,
         String[] fileNames = fileFactories.keySet().toArray(new String[0]);
         for (String fileName : fileNames) {
             FileMessageFactory factory = fileFactories.get(fileName);
-            if (!factory.isValid()) {
-                fileFactories.remove(fileName);
+            if (factory != null && !factory.isValid()) {
+                // Remove with the factory instance to avoid evicting a newer
+                // factory created for a new transfer of the same file
+                fileFactories.remove(fileName, factory);
             }
         }
     }
diff --git a/java/org/apache/catalina/ha/deploy/FileMessageFactory.java 
b/java/org/apache/catalina/ha/deploy/FileMessageFactory.java
index 602f17adf8..0060dbc7a0 100644
--- a/java/org/apache/catalina/ha/deploy/FileMessageFactory.java
+++ b/java/org/apache/catalina/ha/deploy/FileMessageFactory.java
@@ -372,7 +372,7 @@ public class FileMessageFactory {
      *
      * @return True if the factory is still valid, false if it has expired
      */
-    public boolean isValid() {
+    public synchronized boolean isValid() {
         if (maxValidTime > 0) {
             long timeNow = System.currentTimeMillis();
             long timeIdle = (timeNow - lastModified) / 1000L;


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

Reply via email to