From 76b99a2e01c338d51569108cd36fdf10c201f8dc Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 5 Apr 2024 11:18:32 +0200 Subject: [PATCH] Mutex-protect the time conversion in the URLSynchronization to prevent a rare crash when accessing SpiceManager multithreaded --- modules/sync/syncs/urlsynchronization.cpp | 5 ++++- modules/sync/syncs/urlsynchronization.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/sync/syncs/urlsynchronization.cpp b/modules/sync/syncs/urlsynchronization.cpp index f40c55d748..817032e00b 100644 --- a/modules/sync/syncs/urlsynchronization.cpp +++ b/modules/sync/syncs/urlsynchronization.cpp @@ -222,8 +222,11 @@ bool UrlSynchronization::isEachFileValid() { // Valid to: yyyy-mm-ddThr:mn:sc.xxx if (ossyncVersion == "1.0") { + // We need to mutex-protect the access to the time conversion for now + std::lock_guard guard(_mutex); + ghoul::getline(file >> std::ws, line); - std::string& fileIsValidToDate = line; + const std::string& fileIsValidToDate = line; const double fileValidAsJ2000 = Time::convertTime(fileIsValidToDate); const std::string todaysDate = Time::currentWallTime(); diff --git a/modules/sync/syncs/urlsynchronization.h b/modules/sync/syncs/urlsynchronization.h index 6707f7e3bc..b569de3595 100644 --- a/modules/sync/syncs/urlsynchronization.h +++ b/modules/sync/syncs/urlsynchronization.h @@ -122,6 +122,8 @@ private: /// Determines how long the file is valid before it should be downloaded again double _secondsUntilResync = MaxDateAsJ2000; + + std::mutex _mutex; }; } // namespace openspace