From d1afd16955ac4474b598dc34ee6c9e2ce4e9b452 Mon Sep 17 00:00:00 2001 From: Zejun Li Date: Fri, 3 Mar 2017 02:00:22 +0800 Subject: [PATCH] Using RWMutex to guard closing and listeners (#3829) --- cmd/server-mux.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/server-mux.go b/cmd/server-mux.go index 4208a5807..3ef812a5e 100644 --- a/cmd/server-mux.go +++ b/cmd/server-mux.go @@ -334,7 +334,7 @@ type ServerMux struct { // Time to wait before forcing server shutdown gracefulTimeout time.Duration - mu sync.Mutex // guards closing, and listeners + mu sync.RWMutex // guards closing, and listeners closing bool } @@ -461,9 +461,9 @@ func (m *ServerMux) ListenAndServe(certFile, keyFile string) (err error) { // Return ServiceUnavailable for clients which are sending requests // in shutdown phase - m.mu.Lock() + m.mu.RLock() closing := m.closing - m.mu.Unlock() + m.mu.RUnlock() if closing { w.WriteHeader(http.StatusServiceUnavailable) return