Merge pull request #17302 from bprashanth/wait_leak

Fix timer leak in wait.Poll
This commit is contained in:
Prashanth B 2015-11-17 18:35:49 -08:00
commit e82277b86a
2 changed files with 21 additions and 1 deletions

View File

@ -132,7 +132,12 @@ func poller(interval, timeout time.Duration) WaitFunc {
for {
select {
case <-tick.C:
ch <- struct{}{}
// If the consumer isn't ready for this signal drop it and
// check the other channels.
select {
case ch <- struct{}{}:
default:
}
case <-after:
return
case <-done:

View File

@ -257,3 +257,18 @@ func TestWaitFor(t *testing.T) {
}
}
}
func TestWaitForWithDelay(t *testing.T) {
done := make(chan struct{})
defer close(done)
WaitFor(poller(time.Millisecond, util.ForeverTestTimeout), func() (bool, error) {
time.Sleep(10 * time.Millisecond)
return true, nil
}, done)
// If polling goroutine doesn't see the done signal it will leak timers.
select {
case done <- struct{}{}:
case <-time.After(util.ForeverTestTimeout):
t.Errorf("expected an ack of the done signal.")
}
}