@Nullable
    public UserSession authAndUpdateHeartbeatTimestamp(
            long userId,
            @NotNull @ValidDeviceType DeviceType deviceType,
            int sessionId) {
        Validator.notNull(deviceType, "deviceType");
        DeviceTypeUtil.validDeviceType(deviceType);
        UserSessionsManager userSessionsManager = getUserSessionsManager(userId);
        if (userSessionsManager != null) {
            UserSession session = userSessionsManager.getSession(deviceType);
            if (session != null
                    && session.getId() == sessionId
                    && !session.getConnection()
                            .isConnectionRecovering()) {
                session.setLastHeartbeatRequestTimestampToNow();
                return session;
            }
        }
        return null;
    }
@return closed session count
@implNote The method will be called definitely when a session is closed no matter it is
          closed by the client or the server, and the method will clean up sessions in both
          local and Redis.
turms-gateway/src/main/java/im/turms/gateway/domain/session/service/SessionService.java