From e8bcb40735e1abe6393e7242e885177201a35fd8 Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Fri, 6 Sep 2024 00:45:15 +0900 Subject: [PATCH 1/9] add check context cancel Signed-off-by: Kosuke Morimoto --- internal/backoff/backoff.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/backoff/backoff.go b/internal/backoff/backoff.go index 04c1355739..5e8fa1b628 100644 --- a/internal/backoff/backoff.go +++ b/internal/backoff/backoff.go @@ -187,7 +187,22 @@ func (b *backoff) Do( jdur = b.addJitter(dur) } } + + } + } + select { + case <-dctx.Done(): + switch dctx.Err() { + case context.DeadlineExceeded: + log.Debugf("[backoff]\tfor: "+name+",\tDeadline Exceeded\terror: %v", err.Error()) + return nil, errors.ErrBackoffTimeout(err) + case context.Canceled: + log.Debugf("[backoff]\tfor: "+name+",\tCanceled\terror: %v", err.Error()) + return nil, err + default: + return nil, errors.Join(dctx.Err(), err) } + default: } return res, err } From eb7cd8bf8596c2553703cf4dd7117ed0eab4420e Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Fri, 6 Sep 2024 17:47:45 +0900 Subject: [PATCH 2/9] fix Signed-off-by: Kosuke Morimoto --- internal/backoff/backoff_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/internal/backoff/backoff_test.go b/internal/backoff/backoff_test.go index 0549983bbb..e7c6f3ced0 100644 --- a/internal/backoff/backoff_test.go +++ b/internal/backoff/backoff_test.go @@ -533,12 +533,7 @@ func Test_backoff_Do(t *testing.T) { func() test { ctx := context.Background() err := errors.New("erros is occurred") - cnt := 0 f := func(context.Context) (any, bool, error) { - cnt++ - if cnt > 1 { - time.Sleep(10 * time.Millisecond) - } return str, true, err } return test{ From ac1035b3ec7115b7e91bec79060eea6b397660ee Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Fri, 6 Sep 2024 17:58:13 +0900 Subject: [PATCH 3/9] fix Signed-off-by: Kosuke Morimoto --- internal/backoff/backoff.go | 29 ++++++++++++++--------------- internal/backoff/backoff_test.go | 5 +++++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/internal/backoff/backoff.go b/internal/backoff/backoff.go index 5e8fa1b628..d0cc283497 100644 --- a/internal/backoff/backoff.go +++ b/internal/backoff/backoff.go @@ -185,24 +185,23 @@ func (b *backoff) Do( } else { dur *= b.backoffFactor jdur = b.addJitter(dur) + select { + case <-dctx.Done(): + switch dctx.Err() { + case context.DeadlineExceeded: + log.Debugf("[backoff]\tfor: "+name+",\tDeadline Exceeded\terror: %v", err.Error()) + return nil, errors.ErrBackoffTimeout(err) + case context.Canceled: + log.Debugf("[backoff]\tfor: "+name+",\tCanceled\terror: %v", err.Error()) + return nil, err + default: + return nil, errors.Join(dctx.Err(), err) + } + default: + } } } - - } - } - select { - case <-dctx.Done(): - switch dctx.Err() { - case context.DeadlineExceeded: - log.Debugf("[backoff]\tfor: "+name+",\tDeadline Exceeded\terror: %v", err.Error()) - return nil, errors.ErrBackoffTimeout(err) - case context.Canceled: - log.Debugf("[backoff]\tfor: "+name+",\tCanceled\terror: %v", err.Error()) - return nil, err - default: - return nil, errors.Join(dctx.Err(), err) } - default: } return res, err } diff --git a/internal/backoff/backoff_test.go b/internal/backoff/backoff_test.go index e7c6f3ced0..0549983bbb 100644 --- a/internal/backoff/backoff_test.go +++ b/internal/backoff/backoff_test.go @@ -533,7 +533,12 @@ func Test_backoff_Do(t *testing.T) { func() test { ctx := context.Background() err := errors.New("erros is occurred") + cnt := 0 f := func(context.Context) (any, bool, error) { + cnt++ + if cnt > 1 { + time.Sleep(10 * time.Millisecond) + } return str, true, err } return test{ From 48e045289e1c82f18c0db3b4d89c51cc1a739081 Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Fri, 6 Sep 2024 18:03:35 +0900 Subject: [PATCH 4/9] fix Signed-off-by: Kosuke Morimoto --- internal/backoff/backoff.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/internal/backoff/backoff.go b/internal/backoff/backoff.go index d0cc283497..b1407c30d2 100644 --- a/internal/backoff/backoff.go +++ b/internal/backoff/backoff.go @@ -185,19 +185,21 @@ func (b *backoff) Do( } else { dur *= b.backoffFactor jdur = b.addJitter(dur) - select { - case <-dctx.Done(): - switch dctx.Err() { - case context.DeadlineExceeded: - log.Debugf("[backoff]\tfor: "+name+",\tDeadline Exceeded\terror: %v", err.Error()) - return nil, errors.ErrBackoffTimeout(err) - case context.Canceled: - log.Debugf("[backoff]\tfor: "+name+",\tCanceled\terror: %v", err.Error()) - return nil, err + if cnt >= b.maxRetryCount { + select { + case <-dctx.Done(): + switch dctx.Err() { + case context.DeadlineExceeded: + log.Debugf("[backoff]\tfor: "+name+",\tDeadline Exceeded\terror: %v", err.Error()) + return nil, errors.ErrBackoffTimeout(err) + case context.Canceled: + log.Debugf("[backoff]\tfor: "+name+",\tCanceled\terror: %v", err.Error()) + return nil, err + default: + return nil, errors.Join(dctx.Err(), err) + } default: - return nil, errors.Join(dctx.Err(), err) } - default: } } } From bb06ded0f2006e0147bad823d686ba9ca038eac6 Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Fri, 6 Sep 2024 18:15:56 +0900 Subject: [PATCH 5/9] fix Signed-off-by: Kosuke Morimoto --- internal/backoff/backoff.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/backoff/backoff.go b/internal/backoff/backoff.go index b1407c30d2..a9b878db01 100644 --- a/internal/backoff/backoff.go +++ b/internal/backoff/backoff.go @@ -121,7 +121,7 @@ func (b *backoff) Do( dctx, cancel := context.WithDeadline(sctx, time.Now().Add(b.backoffTimeLimit)) defer cancel() - for cnt := 0; cnt < b.maxRetryCount; cnt++ { + for cnt := 1; cnt <= b.maxRetryCount; cnt++ { select { case <-dctx.Done(): switch dctx.Err() { From b1c53f4a84f29b5aec12910f23b9ae5c69c57228 Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Fri, 6 Sep 2024 18:26:43 +0900 Subject: [PATCH 6/9] fix Signed-off-by: Kosuke Morimoto --- internal/backoff/backoff.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/internal/backoff/backoff.go b/internal/backoff/backoff.go index a9b878db01..d0cc283497 100644 --- a/internal/backoff/backoff.go +++ b/internal/backoff/backoff.go @@ -121,7 +121,7 @@ func (b *backoff) Do( dctx, cancel := context.WithDeadline(sctx, time.Now().Add(b.backoffTimeLimit)) defer cancel() - for cnt := 1; cnt <= b.maxRetryCount; cnt++ { + for cnt := 0; cnt < b.maxRetryCount; cnt++ { select { case <-dctx.Done(): switch dctx.Err() { @@ -185,21 +185,19 @@ func (b *backoff) Do( } else { dur *= b.backoffFactor jdur = b.addJitter(dur) - if cnt >= b.maxRetryCount { - select { - case <-dctx.Done(): - switch dctx.Err() { - case context.DeadlineExceeded: - log.Debugf("[backoff]\tfor: "+name+",\tDeadline Exceeded\terror: %v", err.Error()) - return nil, errors.ErrBackoffTimeout(err) - case context.Canceled: - log.Debugf("[backoff]\tfor: "+name+",\tCanceled\terror: %v", err.Error()) - return nil, err - default: - return nil, errors.Join(dctx.Err(), err) - } + select { + case <-dctx.Done(): + switch dctx.Err() { + case context.DeadlineExceeded: + log.Debugf("[backoff]\tfor: "+name+",\tDeadline Exceeded\terror: %v", err.Error()) + return nil, errors.ErrBackoffTimeout(err) + case context.Canceled: + log.Debugf("[backoff]\tfor: "+name+",\tCanceled\terror: %v", err.Error()) + return nil, err default: + return nil, errors.Join(dctx.Err(), err) } + default: } } } From e94820142389313e8e9624c851cdfb976830d160 Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Fri, 6 Sep 2024 18:39:55 +0900 Subject: [PATCH 7/9] fix Signed-off-by: Kosuke Morimoto --- internal/backoff/backoff.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/internal/backoff/backoff.go b/internal/backoff/backoff.go index d0cc283497..2d7860b120 100644 --- a/internal/backoff/backoff.go +++ b/internal/backoff/backoff.go @@ -185,24 +185,24 @@ func (b *backoff) Do( } else { dur *= b.backoffFactor jdur = b.addJitter(dur) - select { - case <-dctx.Done(): - switch dctx.Err() { - case context.DeadlineExceeded: - log.Debugf("[backoff]\tfor: "+name+",\tDeadline Exceeded\terror: %v", err.Error()) - return nil, errors.ErrBackoffTimeout(err) - case context.Canceled: - log.Debugf("[backoff]\tfor: "+name+",\tCanceled\terror: %v", err.Error()) - return nil, err - default: - return nil, errors.Join(dctx.Err(), err) - } - default: - } } } } } + select { + case <-dctx.Done(): + switch dctx.Err() { + case context.DeadlineExceeded: + log.Debugf("[backoff]\tfor: "+name+",\tDeadline Exceeded\terror: %v", err.Error()) + return nil, errors.ErrBackoffTimeout(err) + case context.Canceled: + log.Debugf("[backoff]\tfor: "+name+",\tCanceled\terror: %v", err.Error()) + return nil, err + default: + return nil, errors.Join(dctx.Err(), err) + } + default: + } return res, err } From cdfdfc352936d4ae330271009d2af52fed373e00 Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Mon, 9 Sep 2024 11:04:36 +0900 Subject: [PATCH 8/9] fix Signed-off-by: Kosuke Morimoto --- internal/backoff/backoff.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/internal/backoff/backoff.go b/internal/backoff/backoff.go index 2d7860b120..0c30f6571e 100644 --- a/internal/backoff/backoff.go +++ b/internal/backoff/backoff.go @@ -186,23 +186,25 @@ func (b *backoff) Do( dur *= b.backoffFactor jdur = b.addJitter(dur) } + if cnt >= b.maxRetryCount-1 { + select { + case <-dctx.Done(): + switch dctx.Err() { + case context.DeadlineExceeded: + log.Debugf("[backoff]\tfor: "+name+",\tDeadline Exceeded\terror: %v", err.Error()) + return nil, errors.ErrBackoffTimeout(err) + case context.Canceled: + log.Debugf("[backoff]\tfor: "+name+",\tCanceled\terror: %v", err.Error()) + return nil, err + default: + return nil, errors.Join(dctx.Err(), err) + } + default: + } + } } } } - select { - case <-dctx.Done(): - switch dctx.Err() { - case context.DeadlineExceeded: - log.Debugf("[backoff]\tfor: "+name+",\tDeadline Exceeded\terror: %v", err.Error()) - return nil, errors.ErrBackoffTimeout(err) - case context.Canceled: - log.Debugf("[backoff]\tfor: "+name+",\tCanceled\terror: %v", err.Error()) - return nil, err - default: - return nil, errors.Join(dctx.Err(), err) - } - default: - } return res, err } From a2fdc40ef4afbb51184a4f28f5c87f3e9fbcd600 Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Tue, 10 Sep 2024 10:03:40 +0900 Subject: [PATCH 9/9] update deps Signed-off-by: Kosuke Morimoto --- versions/GO_VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/versions/GO_VERSION b/versions/GO_VERSION index a6c2798a48..49e0a31d49 100644 --- a/versions/GO_VERSION +++ b/versions/GO_VERSION @@ -1 +1 @@ -1.23.0 +1.23.1