From fb95072e5ba61bdf2cb1cdc939067139cbc4207b Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 12 Apr 2023 13:49:29 +0800 Subject: [PATCH] backoff: add default timeout to backoff.RetryGeneral --- pkg/util/backoff/general.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/util/backoff/general.go b/pkg/util/backoff/general.go index e91da06b3..19ae49ace 100644 --- a/pkg/util/backoff/general.go +++ b/pkg/util/backoff/general.go @@ -2,6 +2,7 @@ package backoff import ( "context" + "time" "github.com/cenkalti/backoff/v4" ) @@ -9,7 +10,10 @@ import ( var MaxRetries uint64 = 101 // RetryGeneral retries operation with max retry times 101 and with the exponential backoff -func RetryGeneral(ctx context.Context, op backoff.Operation) (err error) { +func RetryGeneral(parent context.Context, op backoff.Operation) (err error) { + ctx, cancel := context.WithTimeout(parent, 15*time.Minute) + defer cancel() + err = backoff.Retry(op, backoff.WithContext( backoff.WithMaxRetries( backoff.NewExponentialBackOff(),