Fixed rare infinite loops on user session disconnects;
@@ -30,7 +30,7 @@ public enum SessionManager {
if (session.getUserId() != null && !UserManager.instance.getUser(session.getUserId()).isPresent()) {
logger.error("User for session " + sessionId + " with userId " + session.getUserId() + " is missing. Session removed.");
// can happen if user from same host signs in multiple time with multiple clients, after he disconnects with one client
- disconnect(sessionId, DisconnectReason.ConnectingOtherInstance);
+ disconnect(sessionId, DisconnectReason.ConnectingOtherInstance, session); // direct disconnect
return Optional.empty();
}
return Optional.of(session);
@@ -96,6 +96,12 @@ public enum SessionManager {
}
public void disconnect(String sessionId, DisconnectReason reason) {
+ disconnect(sessionId, reason, null);
+ }
+
+ public void disconnect(String sessionId, DisconnectReason reason, Session directSession) {
+ if (directSession == null) {
+ // find real session to disconnects
getSession(sessionId).ifPresent(session -> {
if (!isValidSession(sessionId)) {
// session was removed meanwhile by another thread so we can return
@@ -121,7 +127,11 @@ public enum SessionManager {
logger.trace("endSession: unexpected reason " + reason.toString() + " - sessionId: " + sessionId);
}
});
-
+ } else {
+ // direct session to disconnects
+ sessions.remove(sessionId);
+ directSession.kill(reason);
+ }
}
