mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +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
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user