From f3ded6fd4b95219d1c4382b4fde22c1b2bf8a6f9 Mon Sep 17 00:00:00 2001 From: Luis Weck Date: Sat, 17 Aug 2024 16:28:50 -0300 Subject: [PATCH] fix race condition --- cluster/gossiper.go | 2 +- cluster/kind.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cluster/gossiper.go b/cluster/gossiper.go index b6874da6..dd3465ac 100644 --- a/cluster/gossiper.go +++ b/cluster/gossiper.go @@ -341,7 +341,7 @@ func (g *Gossiper) GetActorCount() map[string]int64 { clusterKinds := g.cluster.GetClusterKinds() for _, kindName := range clusterKinds { kind := g.cluster.GetClusterKind(kindName) - m[kindName] = int64(kind.count) + m[kindName] = int64(kind.Count()) } g.cluster.Logger().Debug("Actor Count", slog.Any("count", m)) diff --git a/cluster/kind.go b/cluster/kind.go index 54493893..2f54ed8c 100644 --- a/cluster/kind.go +++ b/cluster/kind.go @@ -55,3 +55,7 @@ func (ak *ActivatedKind) Inc() { func (ak *ActivatedKind) Dec() { atomic.AddInt32(&ak.count, -1) } + +func (ak *ActivatedKind) Count() int32 { + return atomic.LoadInt32(&ak.count) +}