Commit 006c5f63 authored by jan.koester's avatar jan.koester
Browse files

test

parent caab8201
Loading
Loading
Loading
Loading
Loading
+28 −14
Changes for src/session.cpp: 28 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -454,37 +454,51 @@ const authdb::SessionData *authdb::ClusterSession::addSession(AuthBackend &backe
    std::cerr << "[SESSION] addSession: created sid=" << newSid.c_str()
              << " uid=" << userid.c_str() << " did=" << domainid.c_str() << std::endl;

    // Synchronous push to cluster — blocks until stored
    // Synchronous push to cluster with retry — re-push if verify fails
    if (g_Cluster && g_Cluster->isRunning()) {
        bool verified = false;
        int push_retries = 3;

        for (int retry = 0; retry < push_retries && !verified; ++retry) {
            try {
                g_Cluster->pushSession(*newSession);
            std::cerr << "[SESSION] addSession: pushSession returned OK" << std::endl;
                std::cerr << "[SESSION] addSession: pushSession attempt " << (retry+1) << " OK" << std::endl;
            } catch (const std::exception &e) {
            std::cerr << "[SESSION] addSession: pushSession FAILED: " << e.what() << std::endl;
                std::cerr << "[SESSION] addSession: pushSession attempt " << (retry+1)
                          << " FAILED: " << e.what() << std::endl;
                std::this_thread::sleep_for(std::chrono::milliseconds(200));
                continue;
            }

        // Verify session is retrievable from cluster before returning.
        // This ensures other nodes can serve the session immediately.
        auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(5);
        bool verified = false;
        int attempts = 0;
        while (std::chrono::steady_clock::now() < deadline) {
            ++attempts;
            // Verify session is retrievable from cluster
            auto verify_deadline = std::chrono::steady_clock::now() + std::chrono::seconds(2);
            int checks = 0;
            while (std::chrono::steady_clock::now() < verify_deadline) {
                ++checks;
                uuid::uuid v_sid, v_uid, v_did;
                std::vector<uuid::uuid> v_members;
                std::string v_username;
                std::vector<std::pair<uuid::uuid, bool>> v_gpo;
                if (g_Cluster->fetchSessionBySid(newSid, v_sid, v_uid, v_did,
                                                  v_members, v_username, v_gpo)) {
                std::cerr << "[SESSION] addSession: verified after " << attempts << " attempt(s)" << std::endl;
                    std::cerr << "[SESSION] addSession: verified on attempt " << (retry+1)
                              << " after " << checks << " check(s)" << std::endl;
                    verified = true;
                    break;
                }
            std::this_thread::sleep_for(std::chrono::milliseconds(100));
                std::this_thread::sleep_for(std::chrono::milliseconds(150));
            }

            if (!verified) {
                std::cerr << "[SESSION] addSession: verify FAILED on attempt " << (retry+1)
                          << " after " << checks << " checks — will retry push" << std::endl;
            }
        }

        if (!verified) {
            std::cerr << "[SESSION] addSession: WARNING — session pushed but not verifiable after "
                      << attempts << " attempts (5s)" << std::endl;
            std::cerr << "[SESSION] addSession: ERROR — session not verifiable after "
                      << push_retries << " push attempts" << std::endl;
            throw AuthBackendError("session could not be stored in cluster — please try again");
        }
    }