Skip to content

fix: add exp backoff to validate fresh git auth tokens #8956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix infinite backoff
  • Loading branch information
kylecarbs committed Aug 8, 2023
commit d37f6eab24e05dd616ebecae663fa4529e932cbb
7 changes: 5 additions & 2 deletions coderd/gitauth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ func (c *Config) RefreshToken(ctx context.Context, db database.Store, gitAuthLin
// we aren't trying to surface an error, we're just trying to obtain a valid token.
return gitAuthLink, false, nil
}
r := retry.New(50*time.Millisecond, time.Second)
r := retry.New(50*time.Millisecond, 200*time.Millisecond)
// See the comment below why the retry and cancel is required.
retryCtx, retryCtxCancel := context.WithTimeout(ctx, time.Second)
defer retryCtxCancel()
validate:
valid, _, err := c.ValidateToken(ctx, token.AccessToken)
if err != nil {
Expand All @@ -91,7 +94,7 @@ validate:
// to the read replica in time.
//
// We do an exponential backoff here to give the write time to propagate.
if c.Type == codersdk.GitProviderGitHub && r.Wait(ctx) {
if c.Type == codersdk.GitProviderGitHub && r.Wait(retryCtx) {
goto validate
}
// The token is no longer valid!
Expand Down