From 4f959f2611957d45790c1d7719f228bf109a2acb Mon Sep 17 00:00:00 2001 From: Roman Golov Date: Tue, 17 Sep 2024 17:24:02 +0300 Subject: [PATCH] Fix concurrent map writes in metrics --- CHANGELOG.md | 1 + metrics/driver.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea3eba4e5..a9854d6a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +* Fixed concurrent map writes in metrics * Renamed method at experimental API reader.PopBatchTx to reader.PopMessagesBatchTx ## v3.80.5 diff --git a/metrics/driver.go b/metrics/driver.go index 014853b1d..50d56092d 100644 --- a/metrics/driver.go +++ b/metrics/driver.go @@ -2,6 +2,7 @@ package metrics import ( "strconv" + "sync" "github.com/ydb-platform/ydb-go-sdk/v3/internal/repeater" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" @@ -26,6 +27,7 @@ func driver(config Config) (t trace.Driver) { az string } knownEndpoints := make(map[endpointKey]struct{}) + endpointsMu := sync.RWMutex{} t.OnConnInvoke = func(info trace.DriverConnInvokeStartInfo) func(trace.DriverConnInvokeDoneInfo) { var ( @@ -104,6 +106,8 @@ func driver(config Config) (t trace.Driver) { return func(info trace.DriverBalancerUpdateDoneInfo) { if config.Details()&trace.DriverBalancerEvents != 0 { + endpointsMu.Lock() + defer endpointsMu.Unlock() balancerUpdates.With(map[string]string{ "cause": eventType, }).Inc()