Loading src/backend.cpp +8 −7 Original line number Original line Diff line number Diff line Loading @@ -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"); Loading src/backends/cluster.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -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" Loading Loading @@ -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; }; }; }; }; Loading
src/backend.cpp +8 −7 Original line number Original line Diff line number Diff line Loading @@ -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"); Loading
src/backends/cluster.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -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" Loading Loading @@ -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; }; }; }; };