From 9f886d6e5e5061a846c3eef498a387e29a3bd5ba Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Mon, 3 Jun 2019 19:24:36 +0300 Subject: [PATCH] Fixed - Tomcat Session doesn't expire if broadcastSessionEvents = true #2104 --- .../org/redisson/tomcat/RedissonSession.java | 22 ++++++++++++++++--- .../org/redisson/tomcat/RedissonSession.java | 20 +++++++++++++++-- .../org/redisson/tomcat/RedissonSession.java | 20 +++++++++++++++-- .../org/redisson/tomcat/RedissonSession.java | 20 +++++++++++++++-- 4 files changed, 73 insertions(+), 9 deletions(-) diff --git a/redisson-tomcat/redisson-tomcat-6/src/main/java/org/redisson/tomcat/RedissonSession.java b/redisson-tomcat/redisson-tomcat-6/src/main/java/org/redisson/tomcat/RedissonSession.java index 7a679677f..96e091fe7 100644 --- a/redisson-tomcat/redisson-tomcat-6/src/main/java/org/redisson/tomcat/RedissonSession.java +++ b/redisson-tomcat/redisson-tomcat-6/src/main/java/org/redisson/tomcat/RedissonSession.java @@ -48,10 +48,15 @@ public class RedissonSession extends StandardSession { private static final String MAX_INACTIVE_INTERVAL_ATTR = "session:maxInactiveInterval"; private static final String LAST_ACCESSED_TIME_ATTR = "session:lastAccessedTime"; private static final String CREATION_TIME_ATTR = "session:creationTime"; + private static final String IS_EXPIRATION_LOCKED = "session:isExpirationLocked"; - public static final Set ATTRS = new HashSet(Arrays.asList(IS_NEW_ATTR, IS_VALID_ATTR, - THIS_ACCESSED_TIME_ATTR, MAX_INACTIVE_INTERVAL_ATTR, LAST_ACCESSED_TIME_ATTR, CREATION_TIME_ATTR)); + public static final Set ATTRS = new HashSet(Arrays.asList( + IS_NEW_ATTR, IS_VALID_ATTR, + THIS_ACCESSED_TIME_ATTR, MAX_INACTIVE_INTERVAL_ATTR, + LAST_ACCESSED_TIME_ATTR, CREATION_TIME_ATTR, IS_EXPIRATION_LOCKED + )); + private boolean isExpirationLocked; private boolean loaded; private final RedissonSessionManager redissonManager; private final Map attrs; @@ -147,6 +152,7 @@ public class RedissonSession extends StandardSession { } if (broadcastSessionEvents) { + map.fastPut(IS_EXPIRATION_LOCKED, true); map.expire(60, TimeUnit.SECONDS); } else { map.delete(); @@ -190,6 +196,9 @@ public class RedissonSession extends StandardSession { } protected void expireSession() { + if (isExpirationLocked) { + return; + } if (maxInactiveInterval >= 0) { map.expire(maxInactiveInterval + 60, TimeUnit.SECONDS); } @@ -307,7 +316,10 @@ public class RedissonSession extends StandardSession { newMap.put(MAX_INACTIVE_INTERVAL_ATTR, maxInactiveInterval); newMap.put(IS_VALID_ATTR, isValid); newMap.put(IS_NEW_ATTR, isNew); - + if (broadcastSessionEvents) { + newMap.put(IS_EXPIRATION_LOCKED, isExpirationLocked); + } + if (attrs != null) { for (Entry entry : attrs.entrySet()) { newMap.put(entry.getKey(), entry.getValue()); @@ -356,6 +368,10 @@ public class RedissonSession extends StandardSession { if (isNew != null) { this.isNew = isNew; } + Boolean isExpirationLocked = (Boolean) attrs.remove(IS_EXPIRATION_LOCKED); + if (isExpirationLocked != null) { + this.isExpirationLocked = isExpirationLocked; + } for (Entry entry : attrs.entrySet()) { super.setAttribute(entry.getKey(), entry.getValue(), false); diff --git a/redisson-tomcat/redisson-tomcat-7/src/main/java/org/redisson/tomcat/RedissonSession.java b/redisson-tomcat/redisson-tomcat-7/src/main/java/org/redisson/tomcat/RedissonSession.java index 4fe201f19..c5b480caf 100644 --- a/redisson-tomcat/redisson-tomcat-7/src/main/java/org/redisson/tomcat/RedissonSession.java +++ b/redisson-tomcat/redisson-tomcat-7/src/main/java/org/redisson/tomcat/RedissonSession.java @@ -48,10 +48,15 @@ public class RedissonSession extends StandardSession { private static final String MAX_INACTIVE_INTERVAL_ATTR = "session:maxInactiveInterval"; private static final String LAST_ACCESSED_TIME_ATTR = "session:lastAccessedTime"; private static final String CREATION_TIME_ATTR = "session:creationTime"; + private static final String IS_EXPIRATION_LOCKED = "session:isExpirationLocked"; - public static final Set ATTRS = new HashSet(Arrays.asList(IS_NEW_ATTR, IS_VALID_ATTR, - THIS_ACCESSED_TIME_ATTR, MAX_INACTIVE_INTERVAL_ATTR, LAST_ACCESSED_TIME_ATTR, CREATION_TIME_ATTR)); + public static final Set ATTRS = new HashSet(Arrays.asList( + IS_NEW_ATTR, IS_VALID_ATTR, + THIS_ACCESSED_TIME_ATTR, MAX_INACTIVE_INTERVAL_ATTR, + LAST_ACCESSED_TIME_ATTR, CREATION_TIME_ATTR, IS_EXPIRATION_LOCKED + )); + private boolean isExpirationLocked; private boolean loaded; private final RedissonSessionManager redissonManager; private final Map attrs; @@ -147,6 +152,7 @@ public class RedissonSession extends StandardSession { } if (broadcastSessionEvents) { + map.fastPut(IS_EXPIRATION_LOCKED, true); map.expire(60, TimeUnit.SECONDS); } else { map.delete(); @@ -190,6 +196,9 @@ public class RedissonSession extends StandardSession { } protected void expireSession() { + if (isExpirationLocked) { + return; + } if (maxInactiveInterval >= 0) { map.expire(maxInactiveInterval + 60, TimeUnit.SECONDS); } @@ -307,6 +316,9 @@ public class RedissonSession extends StandardSession { newMap.put(MAX_INACTIVE_INTERVAL_ATTR, maxInactiveInterval); newMap.put(IS_VALID_ATTR, isValid); newMap.put(IS_NEW_ATTR, isNew); + if (broadcastSessionEvents) { + newMap.put(IS_EXPIRATION_LOCKED, isExpirationLocked); + } if (attrs != null) { for (Entry entry : attrs.entrySet()) { @@ -356,6 +368,10 @@ public class RedissonSession extends StandardSession { if (isNew != null) { this.isNew = isNew; } + Boolean isExpirationLocked = (Boolean) attrs.remove(IS_EXPIRATION_LOCKED); + if (isExpirationLocked != null) { + this.isExpirationLocked = isExpirationLocked; + } for (Entry entry : attrs.entrySet()) { super.setAttribute(entry.getKey(), entry.getValue(), false); diff --git a/redisson-tomcat/redisson-tomcat-8/src/main/java/org/redisson/tomcat/RedissonSession.java b/redisson-tomcat/redisson-tomcat-8/src/main/java/org/redisson/tomcat/RedissonSession.java index 4fe201f19..c5b480caf 100644 --- a/redisson-tomcat/redisson-tomcat-8/src/main/java/org/redisson/tomcat/RedissonSession.java +++ b/redisson-tomcat/redisson-tomcat-8/src/main/java/org/redisson/tomcat/RedissonSession.java @@ -48,10 +48,15 @@ public class RedissonSession extends StandardSession { private static final String MAX_INACTIVE_INTERVAL_ATTR = "session:maxInactiveInterval"; private static final String LAST_ACCESSED_TIME_ATTR = "session:lastAccessedTime"; private static final String CREATION_TIME_ATTR = "session:creationTime"; + private static final String IS_EXPIRATION_LOCKED = "session:isExpirationLocked"; - public static final Set ATTRS = new HashSet(Arrays.asList(IS_NEW_ATTR, IS_VALID_ATTR, - THIS_ACCESSED_TIME_ATTR, MAX_INACTIVE_INTERVAL_ATTR, LAST_ACCESSED_TIME_ATTR, CREATION_TIME_ATTR)); + public static final Set ATTRS = new HashSet(Arrays.asList( + IS_NEW_ATTR, IS_VALID_ATTR, + THIS_ACCESSED_TIME_ATTR, MAX_INACTIVE_INTERVAL_ATTR, + LAST_ACCESSED_TIME_ATTR, CREATION_TIME_ATTR, IS_EXPIRATION_LOCKED + )); + private boolean isExpirationLocked; private boolean loaded; private final RedissonSessionManager redissonManager; private final Map attrs; @@ -147,6 +152,7 @@ public class RedissonSession extends StandardSession { } if (broadcastSessionEvents) { + map.fastPut(IS_EXPIRATION_LOCKED, true); map.expire(60, TimeUnit.SECONDS); } else { map.delete(); @@ -190,6 +196,9 @@ public class RedissonSession extends StandardSession { } protected void expireSession() { + if (isExpirationLocked) { + return; + } if (maxInactiveInterval >= 0) { map.expire(maxInactiveInterval + 60, TimeUnit.SECONDS); } @@ -307,6 +316,9 @@ public class RedissonSession extends StandardSession { newMap.put(MAX_INACTIVE_INTERVAL_ATTR, maxInactiveInterval); newMap.put(IS_VALID_ATTR, isValid); newMap.put(IS_NEW_ATTR, isNew); + if (broadcastSessionEvents) { + newMap.put(IS_EXPIRATION_LOCKED, isExpirationLocked); + } if (attrs != null) { for (Entry entry : attrs.entrySet()) { @@ -356,6 +368,10 @@ public class RedissonSession extends StandardSession { if (isNew != null) { this.isNew = isNew; } + Boolean isExpirationLocked = (Boolean) attrs.remove(IS_EXPIRATION_LOCKED); + if (isExpirationLocked != null) { + this.isExpirationLocked = isExpirationLocked; + } for (Entry entry : attrs.entrySet()) { super.setAttribute(entry.getKey(), entry.getValue(), false); diff --git a/redisson-tomcat/redisson-tomcat-9/src/main/java/org/redisson/tomcat/RedissonSession.java b/redisson-tomcat/redisson-tomcat-9/src/main/java/org/redisson/tomcat/RedissonSession.java index 4fe201f19..c5b480caf 100644 --- a/redisson-tomcat/redisson-tomcat-9/src/main/java/org/redisson/tomcat/RedissonSession.java +++ b/redisson-tomcat/redisson-tomcat-9/src/main/java/org/redisson/tomcat/RedissonSession.java @@ -48,10 +48,15 @@ public class RedissonSession extends StandardSession { private static final String MAX_INACTIVE_INTERVAL_ATTR = "session:maxInactiveInterval"; private static final String LAST_ACCESSED_TIME_ATTR = "session:lastAccessedTime"; private static final String CREATION_TIME_ATTR = "session:creationTime"; + private static final String IS_EXPIRATION_LOCKED = "session:isExpirationLocked"; - public static final Set ATTRS = new HashSet(Arrays.asList(IS_NEW_ATTR, IS_VALID_ATTR, - THIS_ACCESSED_TIME_ATTR, MAX_INACTIVE_INTERVAL_ATTR, LAST_ACCESSED_TIME_ATTR, CREATION_TIME_ATTR)); + public static final Set ATTRS = new HashSet(Arrays.asList( + IS_NEW_ATTR, IS_VALID_ATTR, + THIS_ACCESSED_TIME_ATTR, MAX_INACTIVE_INTERVAL_ATTR, + LAST_ACCESSED_TIME_ATTR, CREATION_TIME_ATTR, IS_EXPIRATION_LOCKED + )); + private boolean isExpirationLocked; private boolean loaded; private final RedissonSessionManager redissonManager; private final Map attrs; @@ -147,6 +152,7 @@ public class RedissonSession extends StandardSession { } if (broadcastSessionEvents) { + map.fastPut(IS_EXPIRATION_LOCKED, true); map.expire(60, TimeUnit.SECONDS); } else { map.delete(); @@ -190,6 +196,9 @@ public class RedissonSession extends StandardSession { } protected void expireSession() { + if (isExpirationLocked) { + return; + } if (maxInactiveInterval >= 0) { map.expire(maxInactiveInterval + 60, TimeUnit.SECONDS); } @@ -307,6 +316,9 @@ public class RedissonSession extends StandardSession { newMap.put(MAX_INACTIVE_INTERVAL_ATTR, maxInactiveInterval); newMap.put(IS_VALID_ATTR, isValid); newMap.put(IS_NEW_ATTR, isNew); + if (broadcastSessionEvents) { + newMap.put(IS_EXPIRATION_LOCKED, isExpirationLocked); + } if (attrs != null) { for (Entry entry : attrs.entrySet()) { @@ -356,6 +368,10 @@ public class RedissonSession extends StandardSession { if (isNew != null) { this.isNew = isNew; } + Boolean isExpirationLocked = (Boolean) attrs.remove(IS_EXPIRATION_LOCKED); + if (isExpirationLocked != null) { + this.isExpirationLocked = isExpirationLocked; + } for (Entry entry : attrs.entrySet()) { super.setAttribute(entry.getKey(), entry.getValue(), false);