Merge pull request #76784 from tedyu/health-read

Use read lock in ServeHTTP
This commit is contained in:
Kubernetes Prow Robot 2019-05-01 20:42:19 -07:00 committed by GitHub
commit de83eefd1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -122,7 +122,7 @@ type server struct {
listener Listener
httpFactory HTTPServerFactory
lock sync.Mutex
lock sync.RWMutex
services map[types.NamespacedName]*hcInstance
}
@ -199,15 +199,15 @@ type hcHandler struct {
var _ http.Handler = hcHandler{}
func (h hcHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
h.hcs.lock.Lock()
h.hcs.lock.RLock()
svc, ok := h.hcs.services[h.name]
if !ok || svc == nil {
h.hcs.lock.Unlock()
h.hcs.lock.RUnlock()
klog.Errorf("Received request for closed healthcheck %q", h.name.String())
return
}
count := svc.endpoints
h.hcs.lock.Unlock()
h.hcs.lock.RUnlock()
resp.Header().Set("Content-Type", "application/json")
if count == 0 {