From f989fffbe3157e24e5a19559b367f0fd498ae7f9 Mon Sep 17 00:00:00 2001 From: markt Date: Tue, 14 Jul 2009 17:22:47 +0000 Subject: [PATCH] Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=40380 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 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/java/org/apache/catalina/session/StandardSession.java b/java/org/apache/catalina/session/StandardSession.java index afd425f6e..72f5aff80 100644 --- a/java/org/apache/catalina/session/StandardSession.java +++ b/java/org/apache/catalina/session/StandardSession.java @@ -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 -- 2.11.0