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

commit 729dda1435ed83cbae7147bca4511313efd9e286
Author: opencode <[email protected]>
AuthorDate: Wed Oct 7 11:52:43 2026 +0200

    Report unlimited TTL for sessions that never time out in the Manager
    
    SessionUtils.getTTLForSession assumed a positive max inactive interval.
    A non-positive interval is a supported configuration that means the
    session never times out (a context session timeout of zero is stored as
    -1 minutes and reaches the session as a negative number of seconds), so
    the method returned a negative value whose magnitude grew with the idle
    time. The HTML Manager TTL column rendered it as a growing negative
    duration and sorting by TTL used a meaningless negative key.
    
    Return Long.MAX_VALUE from getTTLForSession for a non-positive interval,
    and display it as "Unlimited" in JspHelper, matching the label used for
    these sessions by the text interface session histogram.
---
 java/org/apache/catalina/manager/JspHelper.java         |  8 ++++++--
 java/org/apache/catalina/manager/util/SessionUtils.java | 10 ++++++++--
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/catalina/manager/JspHelper.java 
b/java/org/apache/catalina/manager/JspHelper.java
index 7c4bdb1937..e1241815d3 100644
--- a/java/org/apache/catalina/manager/JspHelper.java
+++ b/java/org/apache/catalina/manager/JspHelper.java
@@ -136,7 +136,7 @@ public class JspHelper {
      * Returns the formatted time-to-live for the given session.
      *
      * @param in_session the session
-     * @return the formatted TTL string
+     * @return the formatted TTL string, or "Unlimited" for sessions that 
never time out
      */
     public static String getDisplayTTLForSession(Session in_session) {
         try {
@@ -147,7 +147,11 @@ public class JspHelper {
             // ignore: invalidated session
             return "";
         }
-        return secondsToTimeString(SessionUtils.getTTLForSession(in_session) / 
1000);
+        long ttl = SessionUtils.getTTLForSession(in_session);
+        if (ttl == Long.MAX_VALUE) {
+            return "Unlimited";
+        }
+        return secondsToTimeString(ttl / 1000);
     }
 
     /**
diff --git a/java/org/apache/catalina/manager/util/SessionUtils.java 
b/java/org/apache/catalina/manager/util/SessionUtils.java
index a4caac73cb..855477b8d9 100644
--- a/java/org/apache/catalina/manager/util/SessionUtils.java
+++ b/java/org/apache/catalina/manager/util/SessionUtils.java
@@ -253,11 +253,17 @@ public class SessionUtils {
      * Returns the remaining time-to-live for the session in milliseconds.
      *
      * @param in_session The session
-     * @return the remaining TTL in milliseconds, or -1 if the session is 
invalidated
+     * @return the remaining TTL in milliseconds, {@link Long#MAX_VALUE} if 
the session never times out, or -1 if the
+     *         session is invalidated
      */
     public static long getTTLForSession(Session in_session) {
         try {
-            return 1000L * in_session.getMaxInactiveInterval() -
+            int maxInactiveInterval = in_session.getMaxInactiveInterval();
+            if (maxInactiveInterval <= 0) {
+                // A non-positive interval means the session never times out
+                return Long.MAX_VALUE;
+            }
+            return 1000L * maxInactiveInterval -
                     (System.currentTimeMillis() - 
in_session.getThisAccessedTime());
         } catch (IllegalStateException ise) {
             // ignore: invalidated session


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

Reply via email to