diff --git a/broker/src/main/java/io/moquette/persistence/MemorySessionStore.java b/broker/src/main/java/io/moquette/persistence/MemorySessionStore.java index 7f267229..8cb738e7 100755 --- a/broker/src/main/java/io/moquette/persistence/MemorySessionStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemorySessionStore.java @@ -751,11 +751,12 @@ public class MemorySessionStore implements ISessionsStore { public void disableSession(String userId, String clientId) { Session session = sessions.get(clientId); if (session != null && session.getDeleted() == 0 && (userId == null || session.getUsername().equals(userId))) { - mServer.getProcessor().processOffline(session, true, null); - databaseStore.updateSessionDeleted(session.getUsername(), clientId, 1); - ConcurrentSkipListSet sessionSet = getUserSessionSet(session.username); - sessionSet.remove(clientId); - sessions.remove(clientId); + mServer.getProcessor().processOffline(session, true, () -> { + databaseStore.updateSessionDeleted(session.getUsername(), clientId, 1); + ConcurrentSkipListSet sessionSet = getUserSessionSet(session.username); + sessionSet.remove(clientId); + sessions.remove(clientId); + }); } } @@ -773,24 +774,25 @@ public class MemorySessionStore implements ISessionsStore { return; } - mServer.getProcessor().processOffline(session, true, null); - ConcurrentSkipListSet sessionSet = getUserSessionSet(session.username); - sessionSet.remove(clientID); + mServer.getProcessor().processOffline(session, true, () -> { + ConcurrentSkipListSet sessionSet = getUserSessionSet(session.username); + sessionSet.remove(clientID); - // remove also the messages stored of type QoS1/2 - LOG.info("Removing stored messages with QoS 1 and 2. ClientId={}", clientID); + // remove also the messages stored of type QoS1/2 + LOG.info("Removing stored messages with QoS 1 and 2. ClientId={}", clientID); - session.secondPhaseStore.clear(); - session.outboundFlightMessages.clear(); - session.inboundFlightMessages.clear(); + session.secondPhaseStore.clear(); + session.outboundFlightMessages.clear(); + session.inboundFlightMessages.clear(); - LOG.info("Wiping existing subscriptions. ClientId={}", clientID); + LOG.info("Wiping existing subscriptions. ClientId={}", clientID); - //remove also the enqueued messages - dropQueue(clientID); + //remove also the enqueued messages + dropQueue(clientID); - // TODO this missing last step breaks the junit test - sessions.remove(clientID); + // TODO this missing last step breaks the junit test + sessions.remove(clientID); + }); } @Override public boolean isMultiEndpointSupported() { diff --git a/broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java b/broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java index c7af9bf9..8de1d898 100755 --- a/broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java +++ b/broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java @@ -620,13 +620,10 @@ public class ProtocolProcessor { String username = NettyUtils.userName(channel); MemorySessionStore.Session session = m_sessionsStore.getSession(clientID); if(session != null) { - processOffline(session, clearSession, new Runnable() { - @Override - public void run() { - ConnectionDescriptor oldConnDescr = new ConnectionDescriptor(clientID, channel); - if(connectionDescriptors.removeConnection(oldConnDescr)) { - m_interceptor.notifyClientConnectionLost(clientID, username); - } + processOffline(session, clearSession, () -> { + ConnectionDescriptor oldConnDescr = new ConnectionDescriptor(clientID, channel); + if(connectionDescriptors.removeConnection(oldConnDescr)) { + m_interceptor.notifyClientConnectionLost(clientID, username); } }); } else {