Skip to content

Commit

Permalink
Update client API server connect retry condition (#2867)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
redgoat650 and mergify[bot] committed May 7, 2024
1 parent 3477fdc commit f5b4fec
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions pkg/kopia/repository/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,20 @@ import (

const (
defaultConnectMaxListCacheDuration time.Duration = time.Second * 600
kopiaGetRepoParametersError = "unable to get repository parameters"
connectionRefusedError = "connection refused"

// maxConnectRetries with value 100 results in ~23 total minutes of
// retries with the apiConnectBackoff settings defined below.
maxConnectionRetries = 100
)

var apiConnectBackoff = backoff.Backoff{
Factor: 2,
Jitter: false,
Min: 100 * time.Millisecond,
Max: 15 * time.Second,
}

// ConnectToAPIServer connects to the Kopia API server running at the given address
func ConnectToAPIServer(
ctx context.Context,
Expand Down Expand Up @@ -73,19 +84,11 @@ func ConnectToAPIServer(
},
}

err = poll.WaitWithBackoff(ctx, backoff.Backoff{
Factor: 2,
Jitter: false,
Min: 100 * time.Millisecond,
Max: 15 * time.Second,
}, func(c context.Context) (bool, error) {
err = poll.WaitWithBackoffWithRetries(ctx, apiConnectBackoff, maxConnectionRetries, isErrConnectionRefused, func(c context.Context) (bool, error) {
// TODO(@pavan): Modify this to use custom config file path, if required
err := repo.ConnectAPIServer(ctx, kopia.DefaultClientConfigFilePath, serverInfo, userPassphrase, opts)
switch {
case isGetRepoParametersError(err):
if err != nil {
log.Debug().WithError(err).Print("Connecting to the Kopia API Server")
return false, nil
case err != nil:
return false, err
}
return true, nil
Expand Down Expand Up @@ -126,6 +129,6 @@ func repositoryConfigFileName(configFile string) string {
return filepath.Join(os.Getenv("HOME"), ".config", "kopia", "repository.config")
}

func isGetRepoParametersError(err error) bool {
return err != nil && strings.Contains(err.Error(), kopiaGetRepoParametersError)
func isErrConnectionRefused(err error) bool {
return err != nil && strings.Contains(err.Error(), connectionRefusedError)
}

0 comments on commit f5b4fec

Please sign in to comment.