Merge pull request #218 from munnerz/test-race

Automatic merge from submit-queue. 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>.

Enable go race detector and fix race in scheduler

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

Fixes a race condition in the scheduler package and enables the race detector in tests

**Release note**:
```release-note
Fix a race condition in the package responsible for scheduling renewals
```
This commit is contained in:
jetstack-ci-bot 2017-12-01 23:22:58 +00:00 committed by GitHub
commit 28fc543db6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -76,6 +76,7 @@ $(CMDS):
go_test:
go test -v \
-race \
$$(go list ./... | \
grep -v '/vendor/' | \
grep -v '/test/e2e' | \

View File

@ -35,19 +35,18 @@ func NewScheduledWorkQueue(processFunc ProcessFunc) ScheduledWorkQueue {
// Duration has come (since the time Add was called). If an existing Timer for
// obj already exists, the previous timer will be cancelled.
func (s *scheduledWorkQueue) Add(obj interface{}, duration time.Duration) {
s.clearTimer(obj)
// we call Forget before acquiring the workLock in order to avoid deadlock
s.Forget(obj)
s.workLock.Lock()
defer s.workLock.Unlock()
s.work[obj] = time.AfterFunc(duration, func() {
defer s.clearTimer(obj)
defer s.Forget(obj)
s.processFunc(obj)
})
}
// Forget will cancel the timer for the given object, if the timer exists.
func (s *scheduledWorkQueue) Forget(obj interface{}) {
s.clearTimer(obj)
}
func (s *scheduledWorkQueue) clearTimer(obj interface{}) {
s.workLock.Lock()
defer s.workLock.Unlock()
if timer, ok := s.work[obj]; ok {