Skip to content

Commit

Permalink
ATS-33
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed Oct 17, 2022
1 parent aaaa6fc commit 9ea6221
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/appng/tomcat/session/SessionManager.java
Expand Up @@ -227,7 +227,7 @@ public void remove(org.apache.catalina.Session session, boolean expired) {
* Session to be removed
*/
public void removeLocal(org.apache.catalina.Session session) {
if (session.getIdInternal() != null) {
if (null != session && session.getIdInternal() != null) {
org.apache.catalina.Session removed = sessions.remove(session.getIdInternal());
if (log().isTraceEnabled()) {
String message = null == removed ? "%s was not locally cached."
Expand Down
Expand Up @@ -116,21 +116,35 @@ public void processExpires() {
} else {
keys = getPersistentSessions().keySet();
}

if (log.isDebugEnabled()) {
log.debug(String.format("Performing expiration check for %s sessions.", keys.size()));
}

AtomicInteger count = new AtomicInteger(0);
keys.forEach(k -> {
SessionData sessionData = getPersistentSessions().get(k);
try {
Session session = Session.load(this, sessionData);
if (null == session) {
// session is not valid, so manager.remove(session, true) already has been called
// which in turn will remove the session from the local cache and also from the persistent store
count.incrementAndGet();
if (log.isTraceEnabled()) {
log.trace(String.format("%s has been removed by internal expiration", k, mapName));
SessionData sessionData = getPersistentSessions().get(k);
if (null == sessionData) {
if (log.isDebugEnabled()) {
log.debug(String.format("Session %s not found in persistent store.", k));
}
if (sticky) {
removeLocal(sessions.get(k));
}
} else {
Session session = Session.load(this, sessionData);
if (null == session) {
// session is not valid, so manager.remove(session, true) already has been called
// which in turn will remove the session from the local cache and also from the persistent store
count.incrementAndGet();
if (log.isTraceEnabled()) {
log.trace(String.format("%s has been removed by internal expiration", k, mapName));
}
}
}
} catch (Exception e) {
log.error("Error expiring session " + k, e);
} catch (Throwable t) {
log.error("Error expiring session " + k, t);
}
});
long timeEnd = System.currentTimeMillis();
Expand Down

0 comments on commit 9ea6221

Please sign in to comment.