mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +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:
parent
df8551acd2
commit
c280b7cab7
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user