Author: markt Date: Fri Jun 6 10:25:49 2014 New Revision: 1600839 URL: http://svn.apache.org/r1600839 Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56578 Correct regression in the fix for 56339 that prevented sessions from expiring when using clustering. The effect of removing expiring = true; from the DeltaSession is that if parallel calls are made to expire() then there is a slightly greater chance of some of those calls blocking while the first completes. This is because expiring is now set to true a little later.
Added: tomcat/trunk/test/org/apache/catalina/session/TestStandardSession.java (with props) Modified: tomcat/trunk/java/org/apache/catalina/ha/session/DeltaSession.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/catalina/ha/session/DeltaSession.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/session/DeltaSession.java?rev=1600839&r1=1600838&r2=1600839&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/ha/session/DeltaSession.java (original) +++ tomcat/trunk/java/org/apache/catalina/ha/session/DeltaSession.java Fri Jun 6 10:25:49 2014 @@ -446,10 +446,6 @@ public class DeltaSession extends Standa if (manager == null) return; - // Mark this session as "being expired". The flag will be unset in - // the call to super.expire(notify) - expiring = true; - String expiredId = getIdInternal(); if(notifyCluster && expiredId != null && Added: tomcat/trunk/test/org/apache/catalina/session/TestStandardSession.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/session/TestStandardSession.java?rev=1600839&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/catalina/session/TestStandardSession.java (added) +++ tomcat/trunk/test/org/apache/catalina/session/TestStandardSession.java Fri Jun 6 10:25:49 2014 @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.session; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.junit.Assert; +import org.junit.Test; + +import org.apache.catalina.Context; +import org.apache.catalina.ha.tcp.SimpleTcpCluster; +import org.apache.catalina.startup.Tomcat; +import org.apache.catalina.startup.TomcatBaseTest; +import org.apache.tomcat.util.buf.ByteChunk; + +public class TestStandardSession extends TomcatBaseTest { + + /** + * Test session.invalidate() in a clustered environment. + */ + @Test + public void testBug56578a() throws Exception { + doTestInvalidate(true); + } + + @Test + public void testBug56578b() throws Exception { + doTestInvalidate(false); + } + + private void doTestInvalidate(boolean useClustering) throws Exception { + // Setup Tomcat instance + Tomcat tomcat = getTomcatInstance(); + + // Must have a real docBase - just use temp + Context ctx = tomcat.addContext("", System.getProperty("java.io.tmpdir")); + + Tomcat.addServlet(ctx, "bug56578", new Bug56578Servlet()); + ctx.addServletMapping("/bug56578", "bug56578"); + + if (useClustering) { + tomcat.getEngine().setCluster(new SimpleTcpCluster()); + ctx.setDistributable(true); + ctx.setManager(ctx.getCluster().createManager("")); + } + tomcat.start(); + + ByteChunk res = getUrl("http://localhost:" + getPort() + "/bug56578"); + Assert.assertEquals("PASS", res.toString()); + } + + private static class Bug56578Servlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + resp.setContentType("text/plain"); + resp.setCharacterEncoding("UTF-8"); + PrintWriter pw = resp.getWriter(); + + HttpSession session = req.getSession(true); + session.invalidate(); + + // Ugly but the easiest way to test of the session is valid or not + boolean result; + try { + session.getCreationTime(); + result = false; + } catch (IllegalStateException ise) { + result = true; + } + + if (result) { + pw.print("PASS"); + } else { + pw.print("FAIL"); + } + } + } +} Propchange: tomcat/trunk/test/org/apache/catalina/session/TestStandardSession.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1600839&r1=1600838&r2=1600839&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Fri Jun 6 10:25:49 2014 @@ -116,6 +116,10 @@ Tomcat. Patch provided by Greg Wilkins. (markt) </add> <fix> + <bug>56578</bug>: Correct regression in the fix for <bug>56339</bug> + that prevented sessions from expiring when using clustering. (markt) + </fix> + <fix> <bug>56588</bug>: Remove code previously added to enforce the requirements of section 4.4 of the Servlet 3.1 specification. The code is no longer required now that Jasper initialization has been refactored --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org