Merge pull request #44935 from yifan-gu/fix_poll

Automatic merge from submit-queue (batch tested with PRs 44940, 44974, 44935)

apimachinery/pkg/util/wait: Fix potential goroutine leak in pollInternal().

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

Without the change, the wait function wouldn't exit until the timeout
happens, so if the timeout is set to a big value and the Poll() is run
inside a loop, then the total goroutines will increase indefinitely.

This PR fixes the issue by closing the stop channel to tell the wait function
to exit immediately if condition is true or any error happens.
This commit is contained in:
Kubernetes Submit Queue 2017-04-26 20:34:14 -07:00 committed by GitHub
commit 2e7cc0222d

View File

@ -186,7 +186,9 @@ func Poll(interval, timeout time.Duration, condition ConditionFunc) error {
} }
func pollInternal(wait WaitFunc, condition ConditionFunc) error { func pollInternal(wait WaitFunc, condition ConditionFunc) error {
return WaitFor(wait, condition, NeverStop) done := make(chan struct{})
defer close(done)
return WaitFor(wait, condition, done)
} }
// PollImmediate tries a condition func until it returns true, an error, or the timeout // PollImmediate tries a condition func until it returns true, an error, or the timeout