New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is a rule in using go channel: never close a channel in the #45291

merged 1 commit into from May 12, 2017
Jump to file or symbol
Failed to load files and symbols.
+9 −5
Diff settings


Just for now

@@ -90,28 +90,32 @@ 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:
} }
} }
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:
glog.V(2).Infof("eviction: stopping threshold notifier") glog.V(2).Infof("eviction: stopping threshold notifier")
syscall.Close(n.watchfd) syscall.Close(n.watchfd)
syscall.Close(n.controlfd) syscall.Close(n.controlfd)
syscall.Close(n.eventfd) syscall.Close(n.eventfd)
return return
case <-eventCh: case <-eventCh:
glog.V(2).Infof("eviction: threshold crossed") glog.V(2).Infof("eviction: threshold crossed")
ProTip! Use n and p to navigate between commits in a pull request.