diff --git a/pkg/kubelet/eviction/threshold_notifier_linux.go b/pkg/kubelet/eviction/threshold_notifier_linux.go index f9449b3c5b3..2c196452f0a 100644 --- a/pkg/kubelet/eviction/threshold_notifier_linux.go +++ b/pkg/kubelet/eviction/threshold_notifier_linux.go @@ -90,20 +90,25 @@ func NewMemCGThresholdNotifier(path, attribute, threshold, description string, h }, nil } -func getThresholdEvents(eventfd int, eventCh chan<- int) { +func getThresholdEvents(eventfd int, eventCh chan<- struct{}, stopCh <-chan struct{}) { for { buf := make([]byte, 8) _, err := syscall.Read(eventfd, buf) if err != nil { return } - eventCh <- 0 + + select { + case eventCh <- struct{}{}: + case <-stopCh: + return + } } } func (n *memcgThresholdNotifier) Start(stopCh <-chan struct{}) { - eventCh := make(chan int, 1) - go getThresholdEvents(n.eventfd, eventCh) + eventCh := make(chan struct{}) + go getThresholdEvents(n.eventfd, eventCh, stopCh) for { select { case <-stopCh: @@ -111,7 +116,6 @@ func (n *memcgThresholdNotifier) Start(stopCh <-chan struct{}) { syscall.Close(n.watchfd) syscall.Close(n.controlfd) syscall.Close(n.eventfd) - close(eventCh) return case <-eventCh: glog.V(2).Infof("eviction: threshold crossed")