Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Kosuke Morimoto <ksk@vdaas.org>
  • Loading branch information
kmrmt committed Sep 6, 2024
1 parent eb7cd8b commit ac1035b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
29 changes: 14 additions & 15 deletions internal/backoff/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions internal/backoff/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit ac1035b

Please sign in to comment.