(tomcat) branch 9.0.x updated: Add a re-try to mitigate against failures observed under load in testing

[email protected]
Newsgroups gmane.comp.jakarta.tomcat.devel
Message-ID <178653003964.1167948.7720564958228170340@gitbox3-he-fi.apache.org>
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 90bc5af990 Add a re-try to mitigate against failures observed under load in testing
90bc5af990 is described below

commit 90bc5af990368f00d3be7b16bab92544578c4f95
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Aug 12 11:20:04 2026 +0100

    Add a re-try to mitigate against failures observed under load in testing
---
 java/org/apache/catalina/session/FileStore.java | 35 +++++++++++++++++++++----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/java/org/apache/catalina/session/FileStore.java b/java/org/apache/catalina/session/FileStore.java
index d57c9b9864..a8589fdfcd 100644
--- a/java/org/apache/catalina/session/FileStore.java
+++ b/java/org/apache/catalina/session/FileStore.java
@@ -38,6 +38,7 @@ import org.apache.catalina.Globals;
 import org.apache.catalina.Session;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.ExceptionUtils;
 import org.apache.tomcat.util.concurrent.KeyedReentrantReadWriteLock;
 import org.apache.tomcat.util.res.StringManager;
 
@@ -282,11 +283,35 @@ public final class FileStore extends StoreBase {
                     ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(fos))) {
                 ((StandardSession) session).writeObjectData(oos);
             }
-            try {
-                Files.move(tempFile.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING,
-                        StandardCopyOption.ATOMIC_MOVE);
-            } catch (AtomicMoveNotSupportedException e) {
-                Files.move(tempFile.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
+            /*
+             * Failures have been observed with the move when under load in testing. The re-try mechanism is an attempt
+             * to mitigate against those failures.
+             */
+            int attempts = 0;
+            int maxAttempts = 2;
+            while (attempts < maxAttempts) {
+                attempts++;
+                try {
+                    try {
+                        Files.move(tempFile.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING,
+                                StandardCopyOption.ATOMIC_MOVE);
+                    } catch (AtomicMoveNotSupportedException e) {
+                        Files.move(tempFile.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
+                    }
+                    break;
+                } catch (Throwable t) {
+                    ExceptionUtils.handleThrowable(t);
+                    if (attempts < maxAttempts) {
+                        // Brief delay before re-try
+                        try {
+                            Thread.sleep(50);
+                        } catch (InterruptedException e) {
+                            // Ignore. The delay will just be shorter than expected.
+                        }
+                    } else {
+                        throw t;
+                    }
+                }
             }
         } finally {
             try {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.