From 7aa94b7eefde0927a9cd753feae99e148d192123 Mon Sep 17 00:00:00 2001 From: KimMachineGun Date: Wed, 2 Oct 2019 05:59:53 +0900 Subject: [PATCH] health: Use sync.RWMutex instead of sync.Mutex (#3058) --- health/server.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/health/server.go b/health/server.go index c79f9d2a..065069d8 100644 --- a/health/server.go +++ b/health/server.go @@ -35,7 +35,7 @@ import ( // Server implements `service Health`. type Server struct { - mu sync.Mutex + mu sync.RWMutex // If shutdown is true, it's expected all serving status is NOT_SERVING, and // will stay in NOT_SERVING. shutdown bool @@ -54,8 +54,8 @@ func NewServer() *Server { // Check implements `service Health`. func (s *Server) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) { - s.mu.Lock() - defer s.mu.Unlock() + s.mu.RLock() + defer s.mu.RUnlock() if servingStatus, ok := s.statusMap[in.Service]; ok { return &healthpb.HealthCheckResponse{ Status: servingStatus,