From 65381ba66b3f00aeaab268bdde0da2b21908a717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20M=C3=BCller?= Date: Fri, 3 Apr 2020 08:39:41 +0200 Subject: [PATCH] ATS-23 --- .../appng/tomcat/session/mongo/MongoStore.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/appng/tomcat/session/mongo/MongoStore.java b/src/main/java/org/appng/tomcat/session/mongo/MongoStore.java index 99f9d00..c0b48b6 100644 --- a/src/main/java/org/appng/tomcat/session/mongo/MongoStore.java +++ b/src/main/java/org/appng/tomcat/session/mongo/MongoStore.java @@ -61,6 +61,9 @@ */ public class MongoStore extends StoreBase { + /** Name of the Tomcat Thread that cleans up sessions in the background */ + private static final String TOMCAT_SESSION_THREAD = "ContainerBackgroundProcessor"; + /** The currently active session for this thread */ protected ThreadLocal currentSession = new ThreadLocal<>(); @@ -329,7 +332,7 @@ public StandardSession load(String id) throws ClassNotFoundException, IOExceptio session.readObjectData(ois); session.setManager(this.manager); - if (!sticky) { + if (!(sticky || TOMCAT_SESSION_THREAD.equals(threadName))) { BasicDBObject setHost = new BasicDBObject("$set", new BasicDBObject(HOST_PROPERTY, String.format("%s@%s", Thread.currentThread().getName(), hostName))); this.collection.update(sessionQuery, setHost); @@ -352,16 +355,19 @@ public StandardSession load(String id) throws ClassNotFoundException, IOExceptio } private DBObject getMongoSession(String id) { + int waited = 0; DBObject mongoSession; BasicDBObject sessionQuery = sessionQuery(id); if (sticky) { String owningThread = null; String threadName = Thread.currentThread().getName(); - while (waited < maxWaitTime && (owningThread = sessionsInUse.get(id)) != null - && !owningThread.equals(threadName)) { - info("Session %s is still used by thread %s, waiting %sms.", id, owningThread, waitTime); - waited = doWait(waited); + if (!TOMCAT_SESSION_THREAD.equals(threadName)) { + while (waited < maxWaitTime && (owningThread = sessionsInUse.get(id)) != null + && !owningThread.equals(threadName)) { + info("Session %s is still used by thread %s, waiting %sms.", id, owningThread, waitTime); + waited = doWait(waited); + } } mongoSession = this.collection.findOne(sessionQuery); } else {