Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions broker/src/main/java/io/moquette/broker/SessionRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,18 @@ public SessionCreationResult(Session session, CreationModeEnum mode, boolean alr

private void removeExpiredSession(ISessionsRepository.SessionData expiredSession) {
final String expiredAt = expiredSession.expireAt().map(Instant::toString).orElse("UNDEFINED");
LOG.debug("Removing session {}, expired on {}", expiredSession.clientId(), expiredAt);
remove(expiredSession.clientId());
sessionsRepository.delete(expiredSession);

subscriptionsDirectory.removeSharedSubscriptionsForClient(expiredSession.clientId());
final String clientId = expiredSession.clientId();
loopsGroup.routeCommand(clientId, "PurgeSession", () -> {
LOG.debug("Removing session {}, expired on {}", clientId, expiredAt);
final Session session = pool.get(clientId);
boolean success = session.assignState(SessionStatus.DISCONNECTED, SessionStatus.DESTROYED);
if (!success) {
remove(session);
sessionsRepository.delete(expiredSession);
subscriptionsDirectory.removeSharedSubscriptionsForClient(clientId);
}
return null;
});
}

private void trackForRemovalOnExpiration(ISessionsRepository.SessionData session) {
Expand Down Expand Up @@ -501,20 +508,20 @@ private void purgeSessionState(Session session) {
throw new SessionCorruptedException("Session has already changed state: " + session);
}

unsubscribe(session);
remove(session.getClientID());

remove(session);
sessionsRepository.delete(session.getSessionData());
subscriptionsDirectory.removeSharedSubscriptionsForClient(session.getClientID());
}

void remove(String clientID) {
final Session old = pool.remove(clientID);
if (old != null) {
void remove(Session session) {
String clientID = session.getClientID();
if (pool.remove(clientID, session)) {
metricsProvider.removeOpenSession();
unsubscribe(session);
// remove from expired tracker if present
sessionExpirationService.untrack(clientID);
loopsGroup.routeCommand(clientID, "Clean up removed session", () -> {
old.cleanUp();
session.cleanUp();
return null;
});
}
Expand Down