diff --git a/broker/src/main/java/io/moquette/persistence/MemorySessionStore.java b/broker/src/main/java/io/moquette/persistence/MemorySessionStore.java index 3b94a9ff..158b071c 100755 --- a/broker/src/main/java/io/moquette/persistence/MemorySessionStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemorySessionStore.java @@ -333,20 +333,18 @@ public class MemorySessionStore implements ISessionsStore { Session session = sessions.get(clientID); - if (session == null || !session.username.equals(username)) { - if (session != null && !session.username.equals(username)) { - if (userSessions.get(username) != null) { - userSessions.get(username).remove(clientID); - } + if (session != null && !session.username.equals(username)) { + if (userSessions.get(username) != null) { + userSessions.get(username).remove(clientID); } - ClientSession clientSession = new ClientSession(clientID, this); - session = databaseStore.getSession(username, clientID, clientSession); - - if (session == null) { - session = databaseStore.createSession(username, clientID, clientSession, platform); - } - sessions.put(clientID, session); } + ClientSession clientSession = new ClientSession(clientID, this); + session = databaseStore.getSession(username, clientID, clientSession); + + if (session == null) { + session = databaseStore.createSession(username, clientID, clientSession, platform); + } + sessions.put(clientID, session); if (session.getDeleted() > 0) {