Skip to content

Commit

Permalink
ATS-34
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed Jan 25, 2023
1 parent 0c7ce71 commit 80587eb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/appng/tomcat/session/SessionManager.java
Expand Up @@ -67,10 +67,10 @@ public abstract class SessionManager<T> extends ManagerBase {
/**
* Remove the session from the underlying persistent storage
*
* @param session
* the session to remove
* @param id
* the session ID to remove
*/
public abstract void removeInternal(org.apache.catalina.Session session);
public abstract void removeInternal(String id);

public abstract Log log();

Expand Down Expand Up @@ -212,7 +212,7 @@ public void add(org.apache.catalina.Session session) {
@Override
public void remove(org.apache.catalina.Session session, boolean expired) {
super.remove(session, expired);
removeInternal(session);
removeInternal(session.getId());
if (expired && log().isDebugEnabled()) {
String message = String.format(Locale.ENGLISH,
"[%s] %s has expired (created: %s, last accessed: %s, maxLifeTime: %ss, age: %ss)",
Expand Down
Expand Up @@ -3,6 +3,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -143,6 +144,12 @@ public void processExpires() {
if (expireInternal(id, sessionData)) {
count.incrementAndGet();
}
} catch (ObjectStreamException ose) {
log.info(String.format("{} occurred while checking session {} for expiration, so it will be removed: {}",
ose.getClass(), id, ose.getMessage()));
sessions.remove(id);
removeInternal(id);
count.incrementAndGet();
} catch (Throwable t) {
log.error(String.format("Error expiring session %s", id), t);
}
Expand Down Expand Up @@ -193,10 +200,10 @@ protected SessionData findSessionInternal(String id) throws IOException {
}

@Override
public void removeInternal(org.apache.catalina.Session session) {
SessionData removed = getPersistentSessions().remove(session.getId());
public void removeInternal(String id) {
SessionData removed = getPersistentSessions().remove(id);
if (null != removed && log.isTraceEnabled()) {
log.trace(String.format("[%s] %s has been removed from '%s'", removed.getSite(), session.getId(), mapName));
log.trace(String.format("[%s] %s has been removed from '%s'", removed.getSite(), id, mapName));
}
}

Expand Down
Expand Up @@ -20,14 +20,14 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleState;
import org.apache.catalina.Session;
import org.apache.juli.logging.Log;
import org.appng.tomcat.session.SessionData;
import org.appng.tomcat.session.SessionManager;
Expand Down Expand Up @@ -259,8 +259,7 @@ protected void updateSession(String id, SessionData sessionData) throws IOExcept
}

@Override
public void removeInternal(Session session) {
String id = session.getId();
public void removeInternal(String id) {
BasicDBObject sessionQuery = sessionQuery(id);
try {
this.collection.remove(sessionQuery);
Expand All @@ -285,6 +284,12 @@ public void processExpires() {
if (expireInternal(id, loadSession(id, mongoSession))) {
count.incrementAndGet();
}
} catch (ObjectStreamException ose) {
log.info(String.format("{} occurred while checking session {} for expiration, so it will be removed: {}",
ose.getClass(), id, ose.getMessage()));
sessions.remove(id);
removeInternal(id);
count.incrementAndGet();
} catch (Throwable t) {
log.error(String.format("Error expiring session %s", id), t);
}
Expand Down

0 comments on commit 80587eb

Please sign in to comment.