mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #76784 from tedyu/health-read
Use read lock in ServeHTTP
This commit is contained in:
commit
de83eefd1b
@ -122,7 +122,7 @@ type server struct {
|
|||||||
listener Listener
|
listener Listener
|
||||||
httpFactory HTTPServerFactory
|
httpFactory HTTPServerFactory
|
||||||
|
|
||||||
lock sync.Mutex
|
lock sync.RWMutex
|
||||||
services map[types.NamespacedName]*hcInstance
|
services map[types.NamespacedName]*hcInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,15 +199,15 @@ type hcHandler struct {
|
|||||||
var _ http.Handler = hcHandler{}
|
var _ http.Handler = hcHandler{}
|
||||||
|
|
||||||
func (h hcHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
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]
|
svc, ok := h.hcs.services[h.name]
|
||||||
if !ok || svc == nil {
|
if !ok || svc == nil {
|
||||||
h.hcs.lock.Unlock()
|
h.hcs.lock.RUnlock()
|
||||||
klog.Errorf("Received request for closed healthcheck %q", h.name.String())
|
klog.Errorf("Received request for closed healthcheck %q", h.name.String())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
count := svc.endpoints
|
count := svc.endpoints
|
||||||
h.hcs.lock.Unlock()
|
h.hcs.lock.RUnlock()
|
||||||
|
|
||||||
resp.Header().Set("Content-Type", "application/json")
|
resp.Header().Set("Content-Type", "application/json")
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user