Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 1949 invoked from network); 8 May 2006 16:23:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 8 May 2006 16:23:47 -0000 Received: (qmail 68859 invoked by uid 500); 8 May 2006 16:23:05 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 68839 invoked by uid 500); 8 May 2006 16:23:05 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 68828 invoked by uid 99); 8 May 2006 16:23:05 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 May 2006 09:23:05 -0700 X-ASF-Spam-Status: No, hits=1.4 required=10.0 tests=DNS_FROM_RFC_ABUSE,DNS_FROM_RFC_WHOIS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [206.190.53.34] (HELO smtp109.plus.mail.re2.yahoo.com) (206.190.53.34) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 08 May 2006 09:23:04 -0700 Received: (qmail 50645 invoked from network); 8 May 2006 16:22:43 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Received:From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:X-MimeOLE; b=GQLlWYCvMmxfpK1aZuTqry3B04f/ZWOyaLZeqb+WATE9R7uBa7+puEXRAGYNeKfw5Ig2YVRZbk8wYGGaDKYGZwntw2zJ/RVSPOzs5vG+Duiso89d938BbDTgAy5OgbUEUabG9hCRih+eov68B6C6Cyu0N5lpsRgSzhfWl2HvcfI= ; Received: from unknown (HELO tim) (timlucia@12.160.199.10 with login) by smtp109.plus.mail.re2.yahoo.com with SMTP; 8 May 2006 16:22:43 -0000 From: "Tim Lucia" To: "'Tomcat Users List'" Subject: Session last-access/lifetime clustered versus non Date: Mon, 8 May 2006 12:22:40 -0400 Message-ID: <004a01c672bb$a0f01fe0$3a0119ac@tim> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcZyukLc9h56kjaIQ/CHsMDwKrsDoAAAUpgQ X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N All (especially Filip ;-), I have a 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< 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"); %>

This is a simple index.jsp

Session ID<%=session.getId()%>
Session created at<%=format.format(new Date(session.getCreationTime()))%>
Session last accessed at<%=format.format(new Date(session.getLastAccessedTime()))%>
Current time is<%=format.format(new Date())%>
Session max inactive interval<%=session.getMaxInactiveInterval()%>
8<8<8<8<8<8<8<8< web.xml 8<8<8<8<8<8<8<8< Simple Simple Web Application Session Lifecycle Event Listener SessionLifecycleListener simple.SessionLifecycleListener 2 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 ? "" : "[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