This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new bc22beae42 Fix session average life calculation
bc22beae42 is described below
commit bc22beae421624659c735ea86b0248045b13da69
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 df3db194ce..f88b40ecfc 100644
--- a/java/org/apache/catalina/session/ManagerBase.java
+++ b/java/org/apache/catalina/session/ManagerBase.java
@@ -1083,18 +1083,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.getDuration();
counter++;
- // Very careful not to overflow - probably not necessary
- result = (result * ((counter - 1) / counter)) + (timeAlive /
counter);
+ sum += timing.getDuration();
}
}
- return result;
+ return counter > 0 ? (int) (sum / counter) : 0;
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index ea69cbc65b..f5ee7635d2 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -133,6 +133,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]