Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=40380
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 14 Jul 2009 17:22:47 +0000 (17:22 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 14 Jul 2009 17:22:47 +0000 (17:22 +0000)
Correct synchronisation of expire()
Should now only run one per session

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@793981 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/session/StandardSession.java

index afd425f..72f5aff 100644 (file)
@@ -162,7 +162,7 @@ public class StandardSession
      * certain IllegalStateException tests.  NOTE:  This value is not
      * included in the serialized version of this object.
      */
-    protected transient boolean expiring = false;
+    protected transient volatile boolean expiring = false;
 
 
     /**
@@ -220,7 +220,7 @@ public class StandardSession
     /**
      * Flag indicating whether this session is valid or not.
      */
-    protected boolean isValid = false;
+    protected volatile boolean isValid = false;
 
     
     /**
@@ -683,15 +683,20 @@ public class StandardSession
      */
     public void expire(boolean notify) {
 
-        // Mark this session as "being expired" if needed
-        if (expiring)
+        // Check to see if expire is in progress or has previously been called
+        if (expiring || !isValid)
             return;
 
         synchronized (this) {
+            // Check again, now we are inside the sync so this code only runs once
+            // Double check locking - expiring and isValid need to be volatile
+            if (expiring || !isValid)
+                return;
 
             if (manager == null)
                 return;
 
+            // Mark this session as "being expired"
             expiring = true;
         
             // Notify interested application event listeners