in mqtt-cs/src/main/java/org/apache/rocketmq/mqtt/cs/session/loop/SessionLoopImpl.java [197:227]
public Session unloadSession(String clientId, String channelId) {
Session session = null;
try {
synchronized (this) {
session = sessionMap.remove(channelId);
if (clientId == null) {
if (session != null) {
clientId = session.getClientId();
}
}
if (clientId != null && clientMap.containsKey(clientId)) {
clientMap.get(clientId).remove(channelId);
if (clientMap.get(clientId).isEmpty()) {
clientMap.remove(clientId);
}
}
}
inFlyCache.cleanResource(clientId, channelId);
if (session != null) {
matchAction.removeSubscription(session, session.subscriptionSnapshot());
persistOffset(session);
}
} catch (Exception e) {
logger.error("unloadSession fail:{},{}", clientId, channelId, e);
} finally {
if (session != null) {
session.destroy();
}
}
return session;
}