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

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

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


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

commit 0d0d80e14e17e8537794ae9725c1e3ae498876f4
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 6ca0d521c5..4df5bb1faa 100644
--- a/java/org/apache/catalina/session/FileStore.java
+++ b/java/org/apache/catalina/session/FileStore.java
@@ -37,6 +37,7 @@ import org.apache.catalina.Context;
 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;
 
@@ -281,11 +282,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.