mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #17302 from bprashanth/wait_leak
Fix timer leak in wait.Poll
This commit is contained in:
commit
e82277b86a
@ -132,7 +132,12 @@ func poller(interval, timeout time.Duration) WaitFunc {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-tick.C:
|
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:
|
case <-after:
|
||||||
return
|
return
|
||||||
case <-done:
|
case <-done:
|
||||||
|
@ -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.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user