mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-15 06:01:50 +00:00
There is a rule in using go channel: never close a channel in the
receiver side. fix https://github.com/kubernetes/kubernetes/issues/45215 delete the channel close line change the event channel element type to struct{} go fmt eventCh channel is not essential to be buffered
This commit is contained in:
@@ -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")
|
||||||
|
Reference in New Issue
Block a user