health: Use sync.RWMutex instead of sync.Mutex (#3058)

This commit is contained in:
KimMachineGun
2019-10-02 05:59:53 +09:00
committed by Menghan Li
parent 663e4ce0c9
commit 7aa94b7eef

View File

@ -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,