Commit 3d039186 authored by Yifan Gu's avatar Yifan Gu

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.
parent 708d30a8
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment