You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Tim Lucia <ti...@yahoo.com> on 2006/05/08 18:22:40 UTC

Session last-access/lifetime clustered versus non

All (especially Filip ;-),

I have a <distributable/> web app.  When run on a single, non-clustered
Tomcat, it behaves correctly, maintaining the session state essentially
forever.  When run in a cluster, however, the session state is lost (the
session is clearly destroyed.)

The application essentially refreshes a page at less then the timeout value
specified in web.xml.  This should maintain the last access time (and it
does for non-clustered environments.) 

This happens on 5.5.12, and 5.5.17 in both Windows and Linux environments.

I've boiled this down to a very simple JSP, web.xml, and session listener
for anyone who wants to take a stab at it.  The files are included below.
Session timeout is 2 minutes / 120 seconds, and meta-refresh is at 90
seconds.  Here is the output of three page loads for index.jsp:

1st load:

This is a simple index.jsp
Session ID	                  6A4E1FB6E52889FBC6BAF8D298375E27.tim9009
Session created at	      2006-05-128 11:40:29.587
Session last accessed at	2006-05-128 11:40:29.587
Current time is	            2006-05-128 11:40:29.587
Session max inactive interval	120

(New session, all three timestamps are identical)

2nd load (1st refresh):

This is a simple index.jsp
Session ID	                  6A4E1FB6E52889FBC6BAF8D298375E27.tim9009
Session created at	      2006-05-128 11:40:29.587
Session last accessed at	2006-05-128 11:40:29.587
Current time is	            2006-05-128 11:41:59.634
Session max inactive interval	120

(meta-refresh at 90 seconds, current time is ~90 seconds later then last
accessed time)

3rd load (2nd refresh):

This is a simple index.jsp
Session ID	                  6019F1DDD1DC9162A88CD0A4DD0291A2.tim9009
Session created at	      2006-05-128 11:43:29.665
Session last accessed at	2006-05-128 11:43:29.665
Current time is	            2006-05-128 11:43:29.665
Session max inactive interval	120

(Session has been destroyed.  The SessionListener logs the destruction,
about 2 minutes after the last access time from the first page load.

Time: 2006-05-08 11:43:08,806
Thread: ContainerBackgroundProcessor[StandardEngine[Catalina]]
Message: destroy session [ID=6A4E1FB6E52889FBC6BAF8D298375E27.tim9009,
CRE=Mon May 08 11:40:29 EDT 2006, LAST=Mon May 08 11:40:29 EDT 2006,
TMO=120]

Note that the LAST (access time) was not updated by request #2.

)


Here are the relevant files.  I will mail any of the developers a .zip with
everything included (an entire Eclipse project in fact) if requested.

8<8<8<8<8<8<8<8< Simple.xml / context.xml 8<8<8<8<8<8<8< <Context
  docBase="C:/Projects/simple"
  reloadable="true">
</Context>

8<8<8<8<8<8<8<8< index.jsp 8<8<8<8<8<8<8<8< <%@ page import="java.util.Date"
%> <%@ page import="java.text.SimpleDateFormat" %> <%
	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD
HH:mm:ss.SSS"); %> <html> <head> <META http-equiv='Refresh' content='90'>
</head> <body> <h1>This is a simple index.jsp</h1> <table> <tr> <td>Session
ID</td><td><%=session.getId()%></td>
</tr>
<tr>
<td>Session created at</td><td><%=format.format(new
Date(session.getCreationTime()))%></td>
</tr>
<tr>
<td>Session last accessed at</td><td><%=format.format(new
Date(session.getLastAccessedTime()))%></td>
</tr>
<tr>
<tr>
<td>Current time is</td><td><%=format.format(new Date())%></td> </tr> <tr>
<td>Session max inactive
interval</td><td><%=session.getMaxInactiveInterval()%></td>
</tr>
</table>
</body>
</html>

8<8<8<8<8<8<8<8< web.xml 8<8<8<8<8<8<8<8< <?xml version = '1.0' encoding =
'UTF-8'?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

  <distributable/>
  <!-- Display name is used as the mBean name, so it can't contain a ,   -->
  <display-name>Simple</display-name>
  <description>Simple Web Application</description>

  <listener id="SessionLifecycleListener">
    <description>Session Lifecycle Event Listener</description> 
    <display-name>SessionLifecycleListener</display-name> 
    <listener-class>simple.SessionLifecycleListener</listener-class>
  </listener>
  
  <session-config>
    <session-timeout>2</session-timeout>
  </session-config>
</web-app>

8<8<8<8<8<8<8<8< SessionLifecycleListener.java 8<8<8<8<8<8<8<8< package
simple;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SessionLifecycleListener implements HttpSessionListener {
    private final static Log logger =
LogFactory.getLog(SessionLifecycleListener.class);

    public void sessionCreated(HttpSessionEvent arg0) 
    {
        final HttpSession session = arg0.getSession();
        dumpSession("create", session);
    }

    public void sessionDestroyed(HttpSessionEvent arg0) 
    {
        final HttpSession session = arg0.getSession(); 
        dumpSession("destroy", session);
    }
    
    private void dumpSession(String verb, HttpSession session) 
    {
        logger.debug(verb + " session " + formatSession(session));
    }

    public final static String formatSession(HttpSession session)
    {
        return session == null ? "<null session>" :
            "[ID=" + session.getId() + ", CRE=" +
            new Date(session.getCreationTime()) + ", LAST=" +
            new Date(session.getLastAccessedTime()) + ", TMO=" + 
            session.getMaxInactiveInterval() + "]";
    }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Session last-access/lifetime clustered versus non

Posted by Tim Lucia <ti...@yahoo.com>.
This does fix the problem.  Thank you!

-----Original Message-----
From: Filip Hanik - Dev Lists [mailto:devlists@hanik.com] 
Sent: Monday, May 08, 2006 12:43 PM
To: Tomcat Users List
Subject: Re: Session last-access/lifetime clustered versus non

yes, I believe peter just fixed this, here is the SVN commit log,
let me know if this fixes it for you.

Filip


Author: pero
Date: Wed May  3 10:16:15 2006
New Revision: 399358

URL: http://svn.apache.org/viewcvs?rev=399358&view=rev
Log:
Session timeout much shorter than setting at web.xml at cluster environment

Modified:
 
tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/clust
er/session/DeltaSession.java
 
tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session
/DeltaSession.java
    tomcat/container/tc5.5.x/webapps/docs/changelog.xml

Modified:
tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/clust
er/session/DeltaSession.java
URL:
http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/cluster/src/s
hare/org/apache/catalina/cluster/session/DeltaSession.java?rev=399358&r1=399
357&r2=399358&view=diff
============================================================================
==
---
tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/clust
er/session/DeltaSession.java (original)
+++
tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/clust
er/session/DeltaSession.java Wed May  3 10:16:15 2006
@@ -600,7 +600,7 @@
 
         if (maxInactiveInterval >= 0) {
             long timeNow = System.currentTimeMillis();
-            int timeIdle = (int) ((timeNow - lastAccessedTime) / 1000L);
+            int timeIdle = (int) ((timeNow - thisAccessedTime) / 1000L);
             if (isPrimarySession()) {
                 if(timeIdle >= maxInactiveInterval) {
                     expire(true);

Modified:
tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session
/DeltaSession.java
URL:
http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/ha/src/share/
org/apache/catalina/ha/session/DeltaSession.java?rev=399358&r1=399357&r2=399
358&view=diff
============================================================================
==
---
tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session
/DeltaSession.java (original)
+++
tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session
/DeltaSession.java Wed May  3 10:16:15 2006
@@ -636,7 +636,7 @@
         }
         if (maxInactiveInterval >= 0) {
             long timeNow = System.currentTimeMillis();
-            int timeIdle = (int) ( (timeNow - lastAccessedTime) / 1000L);
+            int timeIdle = (int) ( (timeNow - thisAccessedTime) / 1000L);
             if (isPrimarySession()) {
                 if (timeIdle >= maxInactiveInterval) {
                     expire(true);

Modified: tomcat/container/tc5.5.x/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/webapps/docs/changelo
g.xml?rev=399358&r1=399357&r2=399358&view=diff
============================================================================
==
--- tomcat/container/tc5.5.x/webapps/docs/changelog.xml (original)
+++ tomcat/container/tc5.5.x/webapps/docs/changelog.xml Wed May  3 10:16:15
2006
@@ -42,6 +42,14 @@
       </fix>
     </changelog>
   </subsection> 
+  <subsection name="Cluster">
+    <changelog>
+      <fix>
+        <bug>39473</bug>: Session timeout much shorter than setting
+         at web.xml at cluster environment, suggested by Jin Jiang. (pero)
+      </fix>
+    </changelog>
+  </subsection>   
 </section>
 
 <section name="Tomcat 5.5.17 (yoavs)">



Tim Lucia wrote:
> All (especially Filip ;-),
>
> I have a <distributable/> web app.  When run on a single, non-clustered
> Tomcat, it behaves correctly, maintaining the session state essentially
> forever.  When run in a cluster, however, the session state is lost (the
> session is clearly destroyed.)
>
> The application essentially refreshes a page at less then the timeout
value
> specified in web.xml.  This should maintain the last access time (and it
> does for non-clustered environments.) 
>
> This happens on 5.5.12, and 5.5.17 in both Windows and Linux environments.
>
> I've boiled this down to a very simple JSP, web.xml, and session listener
> for anyone who wants to take a stab at it.  The files are included below.
> Session timeout is 2 minutes / 120 seconds, and meta-refresh is at 90
> seconds.  Here is the output of three page loads for index.jsp:
>
> 1st load:
>
> This is a simple index.jsp
> Session ID	                  6A4E1FB6E52889FBC6BAF8D298375E27.tim9009
> Session created at	      2006-05-128 11:40:29.587
> Session last accessed at	2006-05-128 11:40:29.587
> Current time is	            2006-05-128 11:40:29.587
> Session max inactive interval	120
>
> (New session, all three timestamps are identical)
>
> 2nd load (1st refresh):
>
> This is a simple index.jsp
> Session ID	                  6A4E1FB6E52889FBC6BAF8D298375E27.tim9009
> Session created at	      2006-05-128 11:40:29.587
> Session last accessed at	2006-05-128 11:40:29.587
> Current time is	            2006-05-128 11:41:59.634
> Session max inactive interval	120
>
> (meta-refresh at 90 seconds, current time is ~90 seconds later then last
> accessed time)
>
> 3rd load (2nd refresh):
>
> This is a simple index.jsp
> Session ID	                  6019F1DDD1DC9162A88CD0A4DD0291A2.tim9009
> Session created at	      2006-05-128 11:43:29.665
> Session last accessed at	2006-05-128 11:43:29.665
> Current time is	            2006-05-128 11:43:29.665
> Session max inactive interval	120
>
> (Session has been destroyed.  The SessionListener logs the destruction,
> about 2 minutes after the last access time from the first page load.
>
> Time: 2006-05-08 11:43:08,806
> Thread: ContainerBackgroundProcessor[StandardEngine[Catalina]]
> Message: destroy session [ID=6A4E1FB6E52889FBC6BAF8D298375E27.tim9009,
> CRE=Mon May 08 11:40:29 EDT 2006, LAST=Mon May 08 11:40:29 EDT 2006,
> TMO=120]
>
> Note that the LAST (access time) was not updated by request #2.
>
> )
>
>
> Here are the relevant files.  I will mail any of the developers a .zip
with
> everything included (an entire Eclipse project in fact) if requested.
>
> 8<8<8<8<8<8<8<8< Simple.xml / context.xml 8<8<8<8<8<8<8< <Context
>   docBase="C:/Projects/simple"
>   reloadable="true">
> </Context>
>
> 8<8<8<8<8<8<8<8< index.jsp 8<8<8<8<8<8<8<8< <%@ page
import="java.util.Date"
> %> <%@ page import="java.text.SimpleDateFormat" %> <%
> 	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD
> HH:mm:ss.SSS"); %> <html> <head> <META http-equiv='Refresh' content='90'>
> </head> <body> <h1>This is a simple index.jsp</h1> <table> <tr>
<td>Session
> ID</td><td><%=session.getId()%></td>
> </tr>
> <tr>
> <td>Session created at</td><td><%=format.format(new
> Date(session.getCreationTime()))%></td>
> </tr>
> <tr>
> <td>Session last accessed at</td><td><%=format.format(new
> Date(session.getLastAccessedTime()))%></td>
> </tr>
> <tr>
> <tr>
> <td>Current time is</td><td><%=format.format(new Date())%></td> </tr> <tr>
> <td>Session max inactive
> interval</td><td><%=session.getMaxInactiveInterval()%></td>
> </tr>
> </table>
> </body>
> </html>
>
> 8<8<8<8<8<8<8<8< web.xml 8<8<8<8<8<8<8<8< <?xml version = '1.0' encoding =
> 'UTF-8'?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
>     version="2.4">
>
>   <distributable/>
>   <!-- Display name is used as the mBean name, so it can't contain a ,
-->
>   <display-name>Simple</display-name>
>   <description>Simple Web Application</description>
>
>   <listener id="SessionLifecycleListener">
>     <description>Session Lifecycle Event Listener</description> 
>     <display-name>SessionLifecycleListener</display-name> 
>     <listener-class>simple.SessionLifecycleListener</listener-class>
>   </listener>
>   
>   <session-config>
>     <session-timeout>2</session-timeout>
>   </session-config>
> </web-app>
>
> 8<8<8<8<8<8<8<8< SessionLifecycleListener.java 8<8<8<8<8<8<8<8< package
> simple;
>
> import javax.servlet.http.HttpSession;
> import javax.servlet.http.HttpSessionEvent;
> import javax.servlet.http.HttpSessionListener;
>
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
>
> public class SessionLifecycleListener implements HttpSessionListener {
>     private final static Log logger =
> LogFactory.getLog(SessionLifecycleListener.class);
>
>     public void sessionCreated(HttpSessionEvent arg0) 
>     {
>         final HttpSession session = arg0.getSession();
>         dumpSession("create", session);
>     }
>
>     public void sessionDestroyed(HttpSessionEvent arg0) 
>     {
>         final HttpSession session = arg0.getSession(); 
>         dumpSession("destroy", session);
>     }
>     
>     private void dumpSession(String verb, HttpSession session) 
>     {
>         logger.debug(verb + " session " + formatSession(session));
>     }
>
>     public final static String formatSession(HttpSession session)
>     {
>         return session == null ? "<null session>" :
>             "[ID=" + session.getId() + ", CRE=" +
>             new Date(session.getCreationTime()) + ", LAST=" +
>             new Date(session.getLastAccessedTime()) + ", TMO=" + 
>             session.getMaxInactiveInterval() + "]";
>     }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Session last-access/lifetime clustered versus non

Posted by Tim Lucia <ti...@yahoo.com>.
Cool!  Got a workaround for now?  Something we can do to our session state?
Like add a junk variable or something? 

(I will test the SVN head shortly and report back to you.)


-----Original Message-----
From: Filip Hanik - Dev Lists [mailto:devlists@hanik.com] 
Sent: Monday, May 08, 2006 12:43 PM
To: Tomcat Users List
Subject: Re: Session last-access/lifetime clustered versus non

yes, I believe peter just fixed this, here is the SVN commit log, let me
know if this fixes it for you.

Filip


Author: pero
Date: Wed May  3 10:16:15 2006
New Revision: 399358

URL: http://svn.apache.org/viewcvs?rev=399358&view=rev
Log:
Session timeout much shorter than setting at web.xml at cluster environment

Modified:
 
tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/clust
er/session/DeltaSession.java
 
tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session
/DeltaSession.java
    tomcat/container/tc5.5.x/webapps/docs/changelog.xml

Modified:
tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/clust
er/session/DeltaSession.java
URL:
http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/cluster/src/s
hare/org/apache/catalina/cluster/session/DeltaSession.java?rev=399358&r1=399
357&r2=399358&view=diff
============================================================================
==
---
tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/clust
er/session/DeltaSession.java (original)
+++ tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catali
+++ na/cluster/session/DeltaSession.java Wed May  3 10:16:15 2006
@@ -600,7 +600,7 @@
 
         if (maxInactiveInterval >= 0) {
             long timeNow = System.currentTimeMillis();
-            int timeIdle = (int) ((timeNow - lastAccessedTime) / 1000L);
+            int timeIdle = (int) ((timeNow - thisAccessedTime) / 
+ 1000L);
             if (isPrimarySession()) {
                 if(timeIdle >= maxInactiveInterval) {
                     expire(true);

Modified:
tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session
/DeltaSession.java
URL:
http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/ha/src/share/
org/apache/catalina/ha/session/DeltaSession.java?rev=399358&r1=399357&r2=399
358&view=diff
============================================================================
==
---
tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session
/DeltaSession.java (original)
+++ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha
+++ /session/DeltaSession.java Wed May  3 10:16:15 2006
@@ -636,7 +636,7 @@
         }
         if (maxInactiveInterval >= 0) {
             long timeNow = System.currentTimeMillis();
-            int timeIdle = (int) ( (timeNow - lastAccessedTime) / 1000L);
+            int timeIdle = (int) ( (timeNow - thisAccessedTime) / 
+ 1000L);
             if (isPrimarySession()) {
                 if (timeIdle >= maxInactiveInterval) {
                     expire(true);

Modified: tomcat/container/tc5.5.x/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/webapps/docs/changelo
g.xml?rev=399358&r1=399357&r2=399358&view=diff
============================================================================
==
--- tomcat/container/tc5.5.x/webapps/docs/changelog.xml (original)
+++ tomcat/container/tc5.5.x/webapps/docs/changelog.xml Wed May  3 
+++ 10:16:15 2006
@@ -42,6 +42,14 @@
       </fix>
     </changelog>
   </subsection> 
+  <subsection name="Cluster">
+    <changelog>
+      <fix>
+        <bug>39473</bug>: Session timeout much shorter than setting
+         at web.xml at cluster environment, suggested by Jin Jiang. (pero)
+      </fix>
+    </changelog>
+  </subsection>   
 </section>
 
 <section name="Tomcat 5.5.17 (yoavs)">



Tim Lucia wrote:
> All (especially Filip ;-),
>
> I have a <distributable/> web app.  When run on a single, 
> non-clustered Tomcat, it behaves correctly, maintaining the session 
> state essentially forever.  When run in a cluster, however, the 
> session state is lost (the session is clearly destroyed.)
>
> The application essentially refreshes a page at less then the timeout 
> value specified in web.xml.  This should maintain the last access time 
> (and it does for non-clustered environments.)
>
> This happens on 5.5.12, and 5.5.17 in both Windows and Linux environments.
>
> I've boiled this down to a very simple JSP, web.xml, and session 
> listener for anyone who wants to take a stab at it.  The files are
included below.
> Session timeout is 2 minutes / 120 seconds, and meta-refresh is at 90 
> seconds.  Here is the output of three page loads for index.jsp:
>
> 1st load:
>
> This is a simple index.jsp
> Session ID	                  6A4E1FB6E52889FBC6BAF8D298375E27.tim9009
> Session created at	      2006-05-128 11:40:29.587
> Session last accessed at	2006-05-128 11:40:29.587
> Current time is	            2006-05-128 11:40:29.587
> Session max inactive interval	120
>
> (New session, all three timestamps are identical)
>
> 2nd load (1st refresh):
>
> This is a simple index.jsp
> Session ID	                  6A4E1FB6E52889FBC6BAF8D298375E27.tim9009
> Session created at	      2006-05-128 11:40:29.587
> Session last accessed at	2006-05-128 11:40:29.587
> Current time is	            2006-05-128 11:41:59.634
> Session max inactive interval	120
>
> (meta-refresh at 90 seconds, current time is ~90 seconds later then 
> last accessed time)
>
> 3rd load (2nd refresh):
>
> This is a simple index.jsp
> Session ID	                  6019F1DDD1DC9162A88CD0A4DD0291A2.tim9009
> Session created at	      2006-05-128 11:43:29.665
> Session last accessed at	2006-05-128 11:43:29.665
> Current time is	            2006-05-128 11:43:29.665
> Session max inactive interval	120
>
> (Session has been destroyed.  The SessionListener logs the 
> destruction, about 2 minutes after the last access time from the first
page load.
>
> Time: 2006-05-08 11:43:08,806
> Thread: ContainerBackgroundProcessor[StandardEngine[Catalina]]
> Message: destroy session [ID=6A4E1FB6E52889FBC6BAF8D298375E27.tim9009,
> CRE=Mon May 08 11:40:29 EDT 2006, LAST=Mon May 08 11:40:29 EDT 2006, 
> TMO=120]
>
> Note that the LAST (access time) was not updated by request #2.
>
> )
>
>
> Here are the relevant files.  I will mail any of the developers a .zip 
> with everything included (an entire Eclipse project in fact) if requested.
>
> 8<8<8<8<8<8<8<8< Simple.xml / context.xml 8<8<8<8<8<8<8< <Context
>   docBase="C:/Projects/simple"
>   reloadable="true">
> </Context>
>
> 8<8<8<8<8<8<8<8< index.jsp 8<8<8<8<8<8<8<8< <%@ page
import="java.util.Date"
> %> <%@ page import="java.text.SimpleDateFormat" %> <%
> 	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD 
> HH:mm:ss.SSS"); %> <html> <head> <META http-equiv='Refresh' 
> content='90'> </head> <body> <h1>This is a simple index.jsp</h1> 
> <table> <tr> <td>Session ID</td><td><%=session.getId()%></td>
> </tr>
> <tr>
> <td>Session created at</td><td><%=format.format(new 
> Date(session.getCreationTime()))%></td>
> </tr>
> <tr>
> <td>Session last accessed at</td><td><%=format.format(new 
> Date(session.getLastAccessedTime()))%></td>
> </tr>
> <tr>
> <tr>
> <td>Current time is</td><td><%=format.format(new Date())%></td> </tr> 
> <tr> <td>Session max inactive 
> interval</td><td><%=session.getMaxInactiveInterval()%></td>
> </tr>
> </table>
> </body>
> </html>
>
> 8<8<8<8<8<8<8<8< web.xml 8<8<8<8<8<8<8<8< <?xml version = '1.0' 
> encoding = 'UTF-8'?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
>     version="2.4">
>
>   <distributable/>
>   <!-- Display name is used as the mBean name, so it can't contain a ,
-->
>   <display-name>Simple</display-name>
>   <description>Simple Web Application</description>
>
>   <listener id="SessionLifecycleListener">
>     <description>Session Lifecycle Event Listener</description> 
>     <display-name>SessionLifecycleListener</display-name> 
>     <listener-class>simple.SessionLifecycleListener</listener-class>
>   </listener>
>   
>   <session-config>
>     <session-timeout>2</session-timeout>
>   </session-config>
> </web-app>
>
> 8<8<8<8<8<8<8<8< SessionLifecycleListener.java 8<8<8<8<8<8<8<8< 
> package simple;
>
> import javax.servlet.http.HttpSession; import 
> javax.servlet.http.HttpSessionEvent;
> import javax.servlet.http.HttpSessionListener;
>
> import org.apache.commons.logging.Log; import 
> org.apache.commons.logging.LogFactory;
>
> public class SessionLifecycleListener implements HttpSessionListener {
>     private final static Log logger =
> LogFactory.getLog(SessionLifecycleListener.class);
>
>     public void sessionCreated(HttpSessionEvent arg0) 
>     {
>         final HttpSession session = arg0.getSession();
>         dumpSession("create", session);
>     }
>
>     public void sessionDestroyed(HttpSessionEvent arg0) 
>     {
>         final HttpSession session = arg0.getSession(); 
>         dumpSession("destroy", session);
>     }
>     
>     private void dumpSession(String verb, HttpSession session) 
>     {
>         logger.debug(verb + " session " + formatSession(session));
>     }
>
>     public final static String formatSession(HttpSession session)
>     {
>         return session == null ? "<null session>" :
>             "[ID=" + session.getId() + ", CRE=" +
>             new Date(session.getCreationTime()) + ", LAST=" +
>             new Date(session.getLastAccessedTime()) + ", TMO=" + 
>             session.getMaxInactiveInterval() + "]";
>     }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Session last-access/lifetime clustered versus non

Posted by Filip Hanik - Dev Lists <de...@hanik.com>.
yes, I believe peter just fixed this, here is the SVN commit log,
let me know if this fixes it for you.

Filip


Author: pero
Date: Wed May  3 10:16:15 2006
New Revision: 399358

URL: http://svn.apache.org/viewcvs?rev=399358&view=rev
Log:
Session timeout much shorter than setting at web.xml at cluster environment

Modified:
    tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaSession.java
    tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/DeltaSession.java
    tomcat/container/tc5.5.x/webapps/docs/changelog.xml

Modified: tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaSession.java
URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaSession.java?rev=399358&r1=399357&r2=399358&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaSession.java (original)
+++ tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaSession.java Wed May  3 10:16:15 2006
@@ -600,7 +600,7 @@
 
         if (maxInactiveInterval >= 0) {
             long timeNow = System.currentTimeMillis();
-            int timeIdle = (int) ((timeNow - lastAccessedTime) / 1000L);
+            int timeIdle = (int) ((timeNow - thisAccessedTime) / 1000L);
             if (isPrimarySession()) {
                 if(timeIdle >= maxInactiveInterval) {
                     expire(true);

Modified: tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/DeltaSession.java
URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/DeltaSession.java?rev=399358&r1=399357&r2=399358&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/DeltaSession.java (original)
+++ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/DeltaSession.java Wed May  3 10:16:15 2006
@@ -636,7 +636,7 @@
         }
         if (maxInactiveInterval >= 0) {
             long timeNow = System.currentTimeMillis();
-            int timeIdle = (int) ( (timeNow - lastAccessedTime) / 1000L);
+            int timeIdle = (int) ( (timeNow - thisAccessedTime) / 1000L);
             if (isPrimarySession()) {
                 if (timeIdle >= maxInactiveInterval) {
                     expire(true);

Modified: tomcat/container/tc5.5.x/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/webapps/docs/changelog.xml?rev=399358&r1=399357&r2=399358&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/webapps/docs/changelog.xml (original)
+++ tomcat/container/tc5.5.x/webapps/docs/changelog.xml Wed May  3 10:16:15 2006
@@ -42,6 +42,14 @@
       </fix>
     </changelog>
   </subsection> 
+  <subsection name="Cluster">
+    <changelog>
+      <fix>
+        <bug>39473</bug>: Session timeout much shorter than setting
+         at web.xml at cluster environment, suggested by Jin Jiang. (pero)
+      </fix>
+    </changelog>
+  </subsection>   
 </section>
 
 <section name="Tomcat 5.5.17 (yoavs)">



Tim Lucia wrote:
> All (especially Filip ;-),
>
> I have a <distributable/> web app.  When run on a single, non-clustered
> Tomcat, it behaves correctly, maintaining the session state essentially
> forever.  When run in a cluster, however, the session state is lost (the
> session is clearly destroyed.)
>
> The application essentially refreshes a page at less then the timeout value
> specified in web.xml.  This should maintain the last access time (and it
> does for non-clustered environments.) 
>
> This happens on 5.5.12, and 5.5.17 in both Windows and Linux environments.
>
> I've boiled this down to a very simple JSP, web.xml, and session listener
> for anyone who wants to take a stab at it.  The files are included below.
> Session timeout is 2 minutes / 120 seconds, and meta-refresh is at 90
> seconds.  Here is the output of three page loads for index.jsp:
>
> 1st load:
>
> This is a simple index.jsp
> Session ID	                  6A4E1FB6E52889FBC6BAF8D298375E27.tim9009
> Session created at	      2006-05-128 11:40:29.587
> Session last accessed at	2006-05-128 11:40:29.587
> Current time is	            2006-05-128 11:40:29.587
> Session max inactive interval	120
>
> (New session, all three timestamps are identical)
>
> 2nd load (1st refresh):
>
> This is a simple index.jsp
> Session ID	                  6A4E1FB6E52889FBC6BAF8D298375E27.tim9009
> Session created at	      2006-05-128 11:40:29.587
> Session last accessed at	2006-05-128 11:40:29.587
> Current time is	            2006-05-128 11:41:59.634
> Session max inactive interval	120
>
> (meta-refresh at 90 seconds, current time is ~90 seconds later then last
> accessed time)
>
> 3rd load (2nd refresh):
>
> This is a simple index.jsp
> Session ID	                  6019F1DDD1DC9162A88CD0A4DD0291A2.tim9009
> Session created at	      2006-05-128 11:43:29.665
> Session last accessed at	2006-05-128 11:43:29.665
> Current time is	            2006-05-128 11:43:29.665
> Session max inactive interval	120
>
> (Session has been destroyed.  The SessionListener logs the destruction,
> about 2 minutes after the last access time from the first page load.
>
> Time: 2006-05-08 11:43:08,806
> Thread: ContainerBackgroundProcessor[StandardEngine[Catalina]]
> Message: destroy session [ID=6A4E1FB6E52889FBC6BAF8D298375E27.tim9009,
> CRE=Mon May 08 11:40:29 EDT 2006, LAST=Mon May 08 11:40:29 EDT 2006,
> TMO=120]
>
> Note that the LAST (access time) was not updated by request #2.
>
> )
>
>
> Here are the relevant files.  I will mail any of the developers a .zip with
> everything included (an entire Eclipse project in fact) if requested.
>
> 8<8<8<8<8<8<8<8< Simple.xml / context.xml 8<8<8<8<8<8<8< <Context
>   docBase="C:/Projects/simple"
>   reloadable="true">
> </Context>
>
> 8<8<8<8<8<8<8<8< index.jsp 8<8<8<8<8<8<8<8< <%@ page import="java.util.Date"
> %> <%@ page import="java.text.SimpleDateFormat" %> <%
> 	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD
> HH:mm:ss.SSS"); %> <html> <head> <META http-equiv='Refresh' content='90'>
> </head> <body> <h1>This is a simple index.jsp</h1> <table> <tr> <td>Session
> ID</td><td><%=session.getId()%></td>
> </tr>
> <tr>
> <td>Session created at</td><td><%=format.format(new
> Date(session.getCreationTime()))%></td>
> </tr>
> <tr>
> <td>Session last accessed at</td><td><%=format.format(new
> Date(session.getLastAccessedTime()))%></td>
> </tr>
> <tr>
> <tr>
> <td>Current time is</td><td><%=format.format(new Date())%></td> </tr> <tr>
> <td>Session max inactive
> interval</td><td><%=session.getMaxInactiveInterval()%></td>
> </tr>
> </table>
> </body>
> </html>
>
> 8<8<8<8<8<8<8<8< web.xml 8<8<8<8<8<8<8<8< <?xml version = '1.0' encoding =
> 'UTF-8'?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
>     version="2.4">
>
>   <distributable/>
>   <!-- Display name is used as the mBean name, so it can't contain a ,   -->
>   <display-name>Simple</display-name>
>   <description>Simple Web Application</description>
>
>   <listener id="SessionLifecycleListener">
>     <description>Session Lifecycle Event Listener</description> 
>     <display-name>SessionLifecycleListener</display-name> 
>     <listener-class>simple.SessionLifecycleListener</listener-class>
>   </listener>
>   
>   <session-config>
>     <session-timeout>2</session-timeout>
>   </session-config>
> </web-app>
>
> 8<8<8<8<8<8<8<8< SessionLifecycleListener.java 8<8<8<8<8<8<8<8< package
> simple;
>
> import javax.servlet.http.HttpSession;
> import javax.servlet.http.HttpSessionEvent;
> import javax.servlet.http.HttpSessionListener;
>
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
>
> public class SessionLifecycleListener implements HttpSessionListener {
>     private final static Log logger =
> LogFactory.getLog(SessionLifecycleListener.class);
>
>     public void sessionCreated(HttpSessionEvent arg0) 
>     {
>         final HttpSession session = arg0.getSession();
>         dumpSession("create", session);
>     }
>
>     public void sessionDestroyed(HttpSessionEvent arg0) 
>     {
>         final HttpSession session = arg0.getSession(); 
>         dumpSession("destroy", session);
>     }
>     
>     private void dumpSession(String verb, HttpSession session) 
>     {
>         logger.debug(verb + " session " + formatSession(session));
>     }
>
>     public final static String formatSession(HttpSession session)
>     {
>         return session == null ? "<null session>" :
>             "[ID=" + session.getId() + ", CRE=" +
>             new Date(session.getCreationTime()) + ", LAST=" +
>             new Date(session.getLastAccessedTime()) + ", TMO=" + 
>             session.getMaxInactiveInterval() + "]";
>     }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org