From b41ff1f8910f6d5d7e289a8697a8507a106a8c42 Mon Sep 17 00:00:00 2001 From: Naman Jain Date: Thu, 29 Jul 2021 18:14:10 +0530 Subject: [PATCH] fix(pool): use write lock when getting health info (#7963) --- conn/pool.go | 7 ++++--- worker/groups.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/conn/pool.go b/conn/pool.go index ef47e94d679..b8bf74318e3 100644 --- a/conn/pool.go +++ b/conn/pool.go @@ -344,10 +344,11 @@ func (p *Pool) IsHealthy() bool { // HealthInfo returns the healthinfo. func (p *Pool) HealthInfo() pb.HealthInfo { - p.RLock() - defer p.RUnlock() + ok := p.IsHealthy() + p.Lock() + defer p.Unlock() p.healthInfo.Status = "healthy" - if !p.IsHealthy() { + if !ok { p.healthInfo.Status = "unhealthy" } p.healthInfo.LastEcho = p.lastEcho.Unix() diff --git a/worker/groups.go b/worker/groups.go index 8760040fe8b..97ee8cb72a7 100644 --- a/worker/groups.go +++ b/worker/groups.go @@ -58,6 +58,7 @@ type groupi struct { var gr = &groupi{ blockDeletes: new(sync.Mutex), tablets: make(map[string]*pb.Tablet), + closer: z.NewCloser(3), // Match CLOSER:1 in this file. } func groups() *groupi { @@ -155,7 +156,6 @@ func StartRaftNodes(walStore *raftwal.DiskStorage, bindall bool) { gr.Node.InitAndStartNode() glog.Infof("Init and start Raft node: OK") - gr.closer = z.NewCloser(3) // Match CLOSER:1 in this file. go gr.sendMembershipUpdates() go gr.receiveMembershipUpdates() go gr.processOracleDeltaStream()