GUACAMOLE-1299: Merge handle errors that occur while automatically invalidating expired sessions.

This commit is contained in:
Virtually Nick
2021-02-25 10:35:30 -05:00
committed by GitHub

View File

@@ -114,8 +114,13 @@ public class HashTokenSessionMap implements TokenSessionMap {
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
long sessionCheckStart = System.currentTimeMillis();
@@ -129,6 +134,8 @@ public class HashTokenSessionMap implements TokenSessionMap {
Map.Entry<String, GuacamoleSession> entry = entries.next();
GuacamoleSession session = entry.getValue();
try {
// Do not expire sessions which are active
if (session.hasTunnels())
continue;
@@ -143,6 +150,15 @@ public class HashTokenSessionMap implements TokenSessionMap {
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
@@ -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