Commit 26f81759 authored by jan.koester's avatar jan.koester
Browse files

tes

parent 08bf1d62
Loading
Loading
Loading
Loading
Loading
+15 −9
Changes for src/session.cpp: 15 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -477,19 +477,26 @@ const authdb::SessionData *authdb::ClusterSession::addSession(AuthBackend &backe
}

const authdb::SessionData *authdb::ClusterSession::getSession(uuid::uuid sessionid){
    SessionData *cur = nullptr;
    bool needsSync = false;

    {
        std::lock_guard<std::mutex> guard(_lock);
        cleanupExpired();
        SessionData *cur = findLocal(sessionid);
        cur = findLocal(sessionid);
        std::cerr << "[SESSION] getSession: findLocal=" << (cur ? "found" : "null")
                  << " map_size=" << _sessions.size() << std::endl;
        if (cur) {
            if (g_Cluster && g_Cluster->isRunning() && !g_Cluster->isCritical()) {
        if (cur && g_Cluster && g_Cluster->isRunning() && !g_Cluster->isCritical()) {
            auto age = std::chrono::duration_cast<std::chrono::seconds>(
                std::chrono::steady_clock::now() - cur->_lastClusterSync).count();
            std::cerr << "[SESSION] getSession: cluster sync age=" << age
                      << "s critical=" << g_Cluster->isCritical() << std::endl;
                if (age >= 5) {
            needsSync = (age >= 5);
        }
    }

    // Cluster sync OUTSIDE the session lock to avoid blocking other requests
    if (cur && needsSync) {
        uuid::uuid c_sid, c_uid, c_did;
        std::vector<uuid::uuid> c_members;
        std::string c_username;
@@ -498,6 +505,7 @@ const authdb::SessionData *authdb::ClusterSession::getSession(uuid::uuid session
            bool localOk = g_Cluster->fetchSessionLocalBySid(sessionid, c_sid, c_uid, c_did,
                                                  c_members, c_username, c_gpo);
            std::cerr << "[SESSION] getSession: fetchLocalBySid=" << localOk << std::endl;
            std::lock_guard<std::mutex> guard(_lock);
            if (localOk) {
                cur->_members = c_members;
                cur->_username = c_username;
@@ -510,16 +518,14 @@ const authdb::SessionData *authdb::ClusterSession::getSession(uuid::uuid session
                cur->_lastClusterSync = std::chrono::steady_clock::now();
            }
        } catch (const std::exception &e) {
                        // Cluster fetch error — keep local session, retry later
            std::cerr << "[SESSION] getSession: cluster sync error: " << e.what()
                      << ", keeping local session" << std::endl;
            std::lock_guard<std::mutex> guard(_lock);
            cur->_lastClusterSync = std::chrono::steady_clock::now();
        }
    }
            }
            return cur;
        }
    }

    if (cur) return cur;

    // Not found locally — fetch from cluster peers
    if (g_Cluster && g_Cluster->isRunning()) {