From 31c22e5d24605a5f242b987a3fe10e6093736824 Mon Sep 17 00:00:00 2001 From: congqixia Date: Thu, 23 Mar 2023 11:45:57 +0800 Subject: [PATCH] Fix NodeID rw race (#22945) Signed-off-by: Congqi Xia --- internal/util/grpcclient/client.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/util/grpcclient/client.go b/internal/util/grpcclient/client.go index 604264384c..c6f8496d23 100644 --- a/internal/util/grpcclient/client.go +++ b/internal/util/grpcclient/client.go @@ -24,6 +24,7 @@ import ( "time" "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" + "go.uber.org/atomic" "go.uber.org/zap" "golang.org/x/sync/singleflight" "google.golang.org/grpc" @@ -83,7 +84,7 @@ type ClientBase[T interface { InitialBackoff float32 MaxBackoff float32 BackoffMultiplier float32 - NodeID int64 + NodeID atomic.Int64 sf singleflight.Group } @@ -357,10 +358,10 @@ func (c *ClientBase[T]) Close() error { // SetNodeID set ID role of client func (c *ClientBase[T]) SetNodeID(nodeID int64) { - c.NodeID = nodeID + c.NodeID.Store(nodeID) } // GetNodeID returns ID of client func (c *ClientBase[T]) GetNodeID() int64 { - return c.NodeID + return c.NodeID.Load() }