From 1f675f4bb953c5f0af109f24d49a99bfcf8e00f8 Mon Sep 17 00:00:00 2001 From: Jesse Suen Date: Fri, 22 Mar 2019 11:50:00 -0700 Subject: [PATCH] Fix goroutine leak in RetryUntilSucceed (#1314) --- util/util.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util/util.go b/util/util.go index 45517d9a9e..19cbea9392 100644 --- a/util/util.go +++ b/util/util.go @@ -85,10 +85,13 @@ func MakeSignature(size int) ([]byte, error) { // RetryUntilSucceed keep retrying given action with specified timeout until action succeed or specified context is done. func RetryUntilSucceed(action func() error, desc string, ctx context.Context, timeout time.Duration) { ctxCompleted := false + stop := make(chan bool) + defer close(stop) go func() { select { case <-ctx.Done(): ctxCompleted = true + case <-stop: } }() for {