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

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


The following commit(s) were added to refs/heads/11.0.x by this push:
     new 0cc2001ebf Fix session average life calculation
0cc2001ebf is described below

commit 0cc2001ebf083e872131f3faf6870e6013bb289e
Author: remm <[email protected]>
AuthorDate: Wed May 20 16:56:52 2026 +0200

    Fix session average life calculation
---
 java/org/apache/catalina/session/ManagerBase.java | 8 +++-----
 webapps/docs/changelog.xml                        | 3 +++
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/java/org/apache/catalina/session/ManagerBase.java 
b/java/org/apache/catalina/session/ManagerBase.java
index ec484cce15..d0a28575a6 100644
--- a/java/org/apache/catalina/session/ManagerBase.java
+++ b/java/org/apache/catalina/session/ManagerBase.java
@@ -1024,18 +1024,16 @@ public abstract class ManagerBase extends 
LifecycleMBeanBase implements Manager
 
         // Init
         int counter = 0;
-        int result = 0;
+        long sum = 0;
 
         // Calculate average
         for (SessionTiming timing : copy) {
             if (timing != null) {
-                int timeAlive = timing.duration();
                 counter++;
-                // Very careful not to overflow - probably not necessary
-                result = (result * ((counter - 1) / counter)) + (timeAlive / 
counter);
+                sum += timing.duration();
             }
         }
-        return result;
+        return counter > 0 ? (int) (sum / counter) : 0;
     }
 
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index db008a7f97..c216fe51c2 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -137,6 +137,9 @@
         Avoid some NPEs in the Connector class on an uninitialize protocol.
         (remm)
       </fix>
+      <fix>
+        Incorrect session average life calculation. (remm)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">


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

Reply via email to