mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
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:
commit
2e7cc0222d
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user