apiserver: fix Cacher.Stop() race

Kubernetes-commit: a30c0f477d9d4813a08e0abdc7b9029bd4a29287
This commit is contained in:
Dr. Stefan Schimanski 2017-11-06 15:37:07 +01:00 committed by Kubernetes Publisher
parent d5c7d449a9
commit 0d9d3201c2
1 changed files with 5 additions and 3 deletions

View File

@ -649,13 +649,15 @@ func (c *Cacher) isStopped() bool {
}
func (c *Cacher) Stop() {
// TODO : Do not check for isStopped (and return) when PR
// https://github.com/kubernetes/kubernetes/pull/50690
// merges as that shuts down storage properly
// avoid stopping twice (note: cachers are shared with subresources)
if c.isStopped() {
return
}
c.stopLock.Lock()
if c.stopped {
// avoid that it was locked meanwhile as isStopped only read-locks
return
}
c.stopped = true
c.stopLock.Unlock()
close(c.stopCh)