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

commit c61d75f2b4bec88d6862035a7710489162fc8f72
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 d0abf01e29..5a990af774 100644
--- a/java/org/apache/catalina/manager/JspHelper.java
+++ b/java/org/apache/catalina/manager/JspHelper.java
@@ -134,7 +134,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 {
@@ -145,7 +145,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 71890748c0..5751f820c1 100644
--- a/java/org/apache/catalina/manager/util/SessionUtils.java
+++ b/java/org/apache/catalina/manager/util/SessionUtils.java
@@ -219,11 +219,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