mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUACAMOLE-1299: Catch and log all errors that occur while automatically invalidating expired sessions.
This commit is contained in:
@@ -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,18 +134,29 @@ 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();
|
||||||
|
|
||||||
// Do not expire sessions which are active
|
try {
|
||||||
if (session.hasTunnels())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Get elapsed time since last access
|
// Do not expire sessions which are active
|
||||||
long age = sessionCheckStart - session.getLastAccessedTime();
|
if (session.hasTunnels())
|
||||||
|
continue;
|
||||||
|
|
||||||
// If session is too old, evict it and check the next one
|
// Get elapsed time since last access
|
||||||
if (age >= sessionTimeout) {
|
long age = sessionCheckStart - session.getLastAccessedTime();
|
||||||
logger.debug("Session \"{}\" has timed out.", entry.getKey());
|
|
||||||
entries.remove();
|
// If session is too old, evict it and check the next one
|
||||||
session.invalidate();
|
if (age >= sessionTimeout) {
|
||||||
|
logger.debug("Session \"{}\" has timed out.", entry.getKey());
|
||||||
|
entries.remove();
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
Reference in New Issue
Block a user