You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2026/10/01 06:41:34 UTC

(tomcat) 11/25: Synchronize FileMessageFactory.isValid() with the write path and remove expired factories by instance to avoid racing with in-flight transfers

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

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

commit 66206e06a96115db5fd6f6b397c7a7db94b0b80d
Author: opencode <re...@apache.org>
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 9772b2708d..34051a4156 100644
--- a/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
+++ b/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
@@ -803,8 +803,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 25590922c4..5a963da455 100644
--- a/java/org/apache/catalina/ha/deploy/FileMessageFactory.java
+++ b/java/org/apache/catalina/ha/deploy/FileMessageFactory.java
@@ -334,7 +334,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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org