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

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 fix 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:
Yifan Gu 2017-04-25 17:24:40 -07:00
parent 708d30a8d1
commit 3d0391864e

View File

@ -186,7 +186,9 @@ func Poll(interval, timeout time.Duration, 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