Commit 94e34080 authored by jan.koester's avatar jan.koester
Browse files

test

parent 868f7588
Loading
Loading
Loading
Loading
Loading
+8 −7
Original line number Original line Diff line number Diff line
@@ -85,13 +85,14 @@ void authdb::AuthBackend::unlock(){
}
}


void authdb::AuthBackend::lock_shared(){
void authdb::AuthBackend::lock_shared(){
    // Refresh cluster data under exclusive lock (the cluster backend caches
    // Briefly upgrade to exclusive to allow fetchFromCluster, then downgrade.
    // internally for 30 s, so this is usually a no-op).
    // This is safe because _Lock serializes access and the fetch is cached (30 s).
    {
    if (_Lock.try_lock_for(std::chrono::seconds(2))) {
        std::unique_lock<std::shared_timed_mutex> ex(_Lock, std::chrono::milliseconds(200));
        try {
        if (ex.owns_lock()) {
            _Api->lock();
            try { _Api->lock(); _Api->unlock(); } catch (...) {}
            _Api->unlock();
        }
        } catch (...) {}
        _Lock.unlock();
    }
    }
    if (!_Lock.try_lock_shared_for(std::chrono::seconds(5)))
    if (!_Lock.try_lock_shared_for(std::chrono::seconds(5)))
        throw AuthBackendError("backend shared lock timeout");
        throw AuthBackendError("backend shared lock timeout");
+2 −0
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@
#include <cstdint>
#include <cstdint>
#include <atomic>
#include <atomic>
#include <chrono>
#include <chrono>
#include <mutex>


#include "../backend.h"
#include "../backend.h"
#include "../authdb.h"
#include "../authdb.h"
@@ -78,5 +79,6 @@ namespace authdb {
        std::atomic<bool>        _Dirty;
        std::atomic<bool>        _Dirty;
        std::atomic<bool>        _ClusterDataExists{false};
        std::atomic<bool>        _ClusterDataExists{false};
        std::chrono::steady_clock::time_point _LastPeerFetch{};
        std::chrono::steady_clock::time_point _LastPeerFetch{};
        std::mutex               _FetchMutex;
    };
    };
};
};