From 3d0391864ed0a96ac37046e6021a7fa6b9fab313 Mon Sep 17 00:00:00 2001 From: Yifan Gu Date: Tue, 25 Apr 2017 17:24:40 -0700 Subject: [PATCH] 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. --- staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go b/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go index 357c58a3a5e..1538550e3dd 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go @@ -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