Merge pull request #57366 from hzxuzhonghu/cacher-fix

Automatic merge from submit-queue (batch tested with PRs 57366, 57779). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Cacher stopLock should be unlocked

**What this PR does / why we need it**:

Cacher.Stop should also unlock stopLock when isStopped. 
Lock & Unlock should be paired in any case.

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
pull/6/head
Kubernetes Submit Queue 2018-01-03 12:09:32 -08:00 committed by GitHub
commit fcabf0263e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -655,7 +655,7 @@ func (c *Cacher) Stop() {
}
c.stopLock.Lock()
if c.stopped {
// avoid that it was locked meanwhile as isStopped only read-locks
c.stopLock.Unlock()
return
}
c.stopped = true
@ -676,7 +676,7 @@ func forgetWatcher(c *Cacher, index int, triggerValue string, triggerSupported b
glog.V(1).Infof("Forcing watcher close due to unresponsiveness: %v", c.objectType.String())
}
// It's possible that the watcher is already not in the structure (e.g. in case of
// simulaneous Stop() and terminateAllWatchers(), but it doesn't break anything.
// simultaneous Stop() and terminateAllWatchers(), but it doesn't break anything.
c.watchers.deleteWatcher(index, triggerValue, triggerSupported)
}
}
@ -747,7 +747,7 @@ func (lw *cacherListerWatcher) Watch(options metav1.ListOptions) (watch.Interfac
return lw.storage.WatchList(context.TODO(), lw.resourcePrefix, options.ResourceVersion, Everything)
}
// cacherWatch implements watch.Interface to return a single error
// errWatcher implements watch.Interface to return a single error
type errWatcher struct {
result chan watch.Event
}
@ -787,7 +787,7 @@ func (c *errWatcher) Stop() {
// no-op
}
// cacherWatch implements watch.Interface
// cachWatcher implements watch.Interface
type cacheWatcher struct {
sync.Mutex
input chan *watchCacheEvent