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
The following commit(s) were added to refs/heads/main by this push:
new a1e420655c Fix session average life calculation
a1e420655c is described below
commit a1e420655cb15e850ddc8f31844f56bd166eb84d
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 5635490446..a6f2a37acc 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -237,6 +237,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]