This is an automated email from the ASF dual-hosted git repository.
rmaucher 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 43b50c4e9c Fix session average life calculation
43b50c4e9c is described below
commit 43b50c4e9cc6966077b2d3d052e706adadbaa8bf
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 e4d2f5a734..888b802f79 100644
--- a/java/org/apache/catalina/session/ManagerBase.java
+++ b/java/org/apache/catalina/session/ManagerBase.java
@@ -1097,18 +1097,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 9e789d81fa..d0fc2360a4 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -129,6 +129,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]