Allow use of libgit2 built without thread support

With smart transport, users using solely Managed Transports can rely on
Go to deal with the multi-threading requirements of transport
management.

To enable threadless libgit2 an environment variable
ALLOW_THREADLESS_LIBGIT2 must be set to true.

As long as the git2go objects are not being shared across Go routines
this arrangement seems to work well.

By leveraging this and the removal of unmanaged transport we have
experienced a decrease in segfaults or random errors when using git2go
for accessing multiple Git repositories concurrently.

Fixes #917.

Signed-off-by: Paulo Gomes <pjbgf@linux.com>
This commit is contained in:
Paulo Gomes 2022-07-18 16:24:27 +01:00
parent 9db5de109c
commit 63fea0ec6c
No known key found for this signature in database
GPG Key ID: 9995233870E99BEE
1 changed files with 2 additions and 1 deletions

3
git.go
View File

@ -9,6 +9,7 @@ import (
"bytes"
"encoding/hex"
"errors"
"os"
"runtime"
"strings"
"unsafe"
@ -148,7 +149,7 @@ func initLibGit2() {
// with multi-threading support. The most likely outcome is a segfault
// or panic at an incomprehensible time, so let's make it easy by
// panicking right here.
if features&FeatureThreads == 0 {
if features&FeatureThreads == 0 && !strings.EqualFold(os.Getenv("ALLOW_THREADLESS_LIBGIT2"), "true") {
panic("libgit2 was not built with threading support")
}