Skip to content

Commit 8302f4e

Browse files
ash2kEmmanuel326
andcommitted
Merge branch 'runner-wrapper-backoff-context' into 'main'
runner_wrapper: fix backoff retry context cancellation handling See merge request https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/6064 Merged-by: Mikhail Mazurskiy <mmazurskiy@gitlab.com> Approved-by: Mikhail Mazurskiy <mmazurskiy@gitlab.com> Co-authored-by: Emmanuel326 <nyariboemmanuel8@gmail.com>
2 parents 5543322 + 118415b commit 8302f4e

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

helpers/runner_wrapper/api/client/backoff.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ func RetryWithBackoff(ctx context.Context, timeout time.Duration, fn func() erro
1818

1919
var err error
2020

21-
cctx, cancelFn := context.WithDeadlineCause(ctx, time.Now().Add(timeout), fmt.Errorf("%w: %s", ErrRetryTimeoutExceeded, timeout))
21+
cctx, cancelFn := context.WithDeadlineCause(
22+
ctx,
23+
time.Now().Add(timeout),
24+
fmt.Errorf("%w: %s", ErrRetryTimeoutExceeded, timeout),
25+
)
2226
defer cancelFn()
2327

2428
for {
@@ -27,10 +31,15 @@ func RetryWithBackoff(ctx context.Context, timeout time.Duration, fn func() erro
2731
return nil
2832
}
2933

34+
timer := time.NewTimer(b.NextBackOff())
35+
3036
select {
3137
case <-cctx.Done():
32-
return ctx.Err()
33-
case <-time.After(b.NextBackOff()):
38+
timer.Stop()
39+
return cctx.Err()
40+
case <-timer.C:
41+
// continue retrying
3442
}
3543
}
3644
}
45+

0 commit comments

Comments
 (0)