GUACAMOLE-1299: Catch and log all errors that occur while automatically invalidating expired sessions.

This commit is contained in:
Michael Jumper
2020-09-05 13:27:41 -07:00
parent 5da596137c
commit b1dcec7ca9

View File

@@ -114,8 +114,13 @@ public class HashTokenSessionMap implements TokenSessionMap {
this.sessionTimeout = sessionTimeout; this.sessionTimeout = sessionTimeout;
} }
@Override /**
public void run() { * Iterates through all active sessions, evicting those sessions which
* are beyond the session timeout. Internal errors which would
* otherwise stop the session eviction process are caught, logged, and
* the process is allowed to proceed.
*/
private void evictExpiredSessions() {
// Get start time of session check time // Get start time of session check time
long sessionCheckStart = System.currentTimeMillis(); long sessionCheckStart = System.currentTimeMillis();
@@ -129,6 +134,8 @@ public class HashTokenSessionMap implements TokenSessionMap {
Map.Entry<String, GuacamoleSession> entry = entries.next(); Map.Entry<String, GuacamoleSession> entry = entries.next();
GuacamoleSession session = entry.getValue(); GuacamoleSession session = entry.getValue();
try {
// Do not expire sessions which are active // Do not expire sessions which are active
if (session.hasTunnels()) if (session.hasTunnels())
continue; continue;
@@ -143,6 +150,15 @@ public class HashTokenSessionMap implements TokenSessionMap {
session.invalidate(); session.invalidate();
} }
}
catch (Throwable t) {
logger.error("An unexpected internal error prevented a "
+ "session from being invalidated. This should "
+ "NOT happen and is likely a bug. Depending on "
+ "the nature of the failure, the session may "
+ "still be valid.", t);
}
} }
// Log completion and duration // Log completion and duration
@@ -151,6 +167,27 @@ public class HashTokenSessionMap implements TokenSessionMap {
} }
@Override
public void run() {
// The evictExpiredSessions() function should already
// automatically handle and log all unexpected internal errors,
// but wrap the entire call in a try/catch plus additional logging
// to ensure that absolutely no errors can result in the entire
// thread dying
try {
evictExpiredSessions();
}
catch (Throwable t) {
logger.error("An unexpected internal error prevented the "
+ "session eviction task from completing "
+ "successfully. This should NOT happen and is likely "
+ "a bug. Sessions that should have expired may "
+ "remain valid.", t);
}
}
} }
@Override @Override