Commit 2e7cc022 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

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.
parents c446132a 3d039186
......@@ -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