From 09402100946e6892ebd1e75773eb390cdd7f28ab Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Fri, 12 May 2023 13:14:26 +0200 Subject: memcheck: fix race in libgit2... ...caused by incorrectly setting and resetting the library internal state and the misuse of pthreads in libgit2. Normally, git_libgit2_init and git_libgit2_shutdown should span the life of a worker thread in order to be safely used. However, due to an incorrect implementation of libgit2's threadstate with pthreads, on unix systems there is a race condition. Until the use of pthread_key_t is corrected in libgit2, we need to apply a workaround by always ensuring that the main thread is the first thread reaching the GitContext constructor. --- src/buildtool/file_system/git_cas.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/buildtool/file_system/git_cas.hpp') diff --git a/src/buildtool/file_system/git_cas.hpp b/src/buildtool/file_system/git_cas.hpp index f95cb403..3ef8b6d8 100644 --- a/src/buildtool/file_system/git_cas.hpp +++ b/src/buildtool/file_system/git_cas.hpp @@ -34,7 +34,7 @@ class GitCAS { static auto Open(std::filesystem::path const& repo_path) noexcept -> GitCASPtr; - GitCAS() noexcept = default; + GitCAS() noexcept; ~GitCAS() noexcept = default; // prohibit moves and copies @@ -62,8 +62,6 @@ class GitCAS { -> std::optional>; private: - // IMPORTANT: the GitContext needs to be initialized before any git object! - GitContext git_context_{}; // maintains a Git context while CAS is alive std::unique_ptr odb_{nullptr, odb_closer}; // git folder path of repo std::filesystem::path git_path_{}; -- cgit v1.2.3