mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 05:21:58 +00:00
Merge pull request #45291 from yaxinlx/feature-request/fix-kubelet-channel-close
Automatic merge from submit-queue There is a rule in using go channel: never close a channel in the receiver side. fix https://github.com/kubernetes/kubernetes/issues/45215
This commit is contained in:
commit
6c50ffcf7b
@ -90,20 +90,25 @@ func NewMemCGThresholdNotifier(path, attribute, threshold, description string, h
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getThresholdEvents(eventfd int, eventCh chan<- int) {
|
func getThresholdEvents(eventfd int, eventCh chan<- struct{}, stopCh <-chan struct{}) {
|
||||||
for {
|
for {
|
||||||
buf := make([]byte, 8)
|
buf := make([]byte, 8)
|
||||||
_, err := syscall.Read(eventfd, buf)
|
_, err := syscall.Read(eventfd, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
eventCh <- 0
|
|
||||||
|
select {
|
||||||
|
case eventCh <- struct{}{}:
|
||||||
|
case <-stopCh:
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *memcgThresholdNotifier) Start(stopCh <-chan struct{}) {
|
func (n *memcgThresholdNotifier) Start(stopCh <-chan struct{}) {
|
||||||
eventCh := make(chan int, 1)
|
eventCh := make(chan struct{})
|
||||||
go getThresholdEvents(n.eventfd, eventCh)
|
go getThresholdEvents(n.eventfd, eventCh, stopCh)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-stopCh:
|
case <-stopCh:
|
||||||
@ -111,7 +116,6 @@ func (n *memcgThresholdNotifier) Start(stopCh <-chan struct{}) {
|
|||||||
syscall.Close(n.watchfd)
|
syscall.Close(n.watchfd)
|
||||||
syscall.Close(n.controlfd)
|
syscall.Close(n.controlfd)
|
||||||
syscall.Close(n.eventfd)
|
syscall.Close(n.eventfd)
|
||||||
close(eventCh)
|
|
||||||
return
|
return
|
||||||
case <-eventCh:
|
case <-eventCh:
|
||||||
glog.V(2).Infof("eviction: threshold crossed")
|
glog.V(2).Infof("eviction: threshold crossed")
|
||||||
|
Loading…
Reference in New Issue
Block a user