Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-11-02 16:51:40 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-11-08 17:40:32 +0300
commit5e1194f599fda788dbf19180ac4ee853dae49e64 (patch)
tree3d75d5a173cb877264c50fd42871b5cfe6d80aba
parent5439315daae98c468fe71438e4b93f19eab8c72e (diff)
catfile: Make tracing safe for concurrent use
We're about to convert the catfile package to use request queues, and in that world it's possible for Go to observe data races in our tracing. Prepare for that by locking the trace when either recording new requests or when finishing up the tracing span.
-rw-r--r--internal/git/catfile/tracing.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/internal/git/catfile/tracing.go b/internal/git/catfile/tracing.go
index ab2a76d3d..25fd68635 100644
--- a/internal/git/catfile/tracing.go
+++ b/internal/git/catfile/tracing.go
@@ -2,6 +2,7 @@ package catfile
import (
"context"
+ "sync"
"github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus"
@@ -11,7 +12,8 @@ type trace struct {
span opentracing.Span
counter *prometheus.CounterVec
- requests map[string]int
+ requestsLock sync.Mutex
+ requests map[string]int
}
// startTrace starts a new tracing span and updates metrics according to how many requests have been
@@ -41,10 +43,15 @@ func startTrace(
}
func (t *trace) recordRequest(requestType string) {
+ t.requestsLock.Lock()
+ defer t.requestsLock.Unlock()
t.requests[requestType]++
}
func (t *trace) finish() {
+ t.requestsLock.Lock()
+ defer t.requestsLock.Unlock()
+
for requestType, requestCount := range t.requests {
if requestCount == 0 {
continue