Skip to content
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

Retry SSH resolution 5 times #2934

Merged
merged 7 commits into from Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/man/git-lfs-config.5.ronn
Expand Up @@ -51,6 +51,11 @@ be scoped inside the configuration for a remote.
Sets the maximum time, in seconds, for the HTTP client to maintain keepalive
connections. Default: 30 minutes.

* `lfs.ssh.retries`

Specifies the number of times Git LFS will attempt to obtain authorization via
SSH before aborting. Default: 5.

* `core.askpass`, GIT_ASKPASS

Given as a program and its arguments, this is invoked when authentication is
Expand Down
33 changes: 25 additions & 8 deletions lfsapi/client.go
Expand Up @@ -40,15 +40,8 @@ func (c *Client) NewRequest(method string, e Endpoint, suffix string, body inter
fmt.Fprintf(os.Stderr, "\n%s\n", hintFileUrl)
}

sshRes, err := c.SSH.Resolve(e, method)
sshRes, err := c.sshResolveWithRetries(e, method)
if err != nil {
tracerx.Printf("ssh: %s failed, error: %s, message: %s",
e.SshUserAndHost, err.Error(), sshRes.Message,
)

if len(sshRes.Message) > 0 {
return nil, errors.Wrap(err, sshRes.Message)
}
return nil, err
}

Expand Down Expand Up @@ -118,6 +111,30 @@ func (c *Client) Close() error {
return c.httpLogger.Close()
}

func (c *Client) sshResolveWithRetries(e Endpoint, method string) (*sshAuthResponse, error) {
var sshRes sshAuthResponse
var err error

requests := tools.MaxInt(0, c.sshTries) + 1
for i := 0; i < requests; i++ {
sshRes, err = c.SSH.Resolve(e, method)
if err == nil {
return &sshRes, nil
}

tracerx.Printf(
"ssh: %s failed, error: %s, message: %s (try: %d/%d)",
e.SshUserAndHost, err.Error(), sshRes.Message, i,
requests,
)
}

if len(sshRes.Message) > 0 {
return nil, errors.Wrap(err, sshRes.Message)
}
return nil, err
}

func (c *Client) extraHeadersFor(req *http.Request) http.Header {
extraHeaders := c.extraHeaders(req.URL)
if len(extraHeaders) == 0 {
Expand Down
9 changes: 6 additions & 3 deletions lfsapi/lfsapi.go
Expand Up @@ -51,6 +51,8 @@ type Client struct {
gitEnv config.Environment
osEnv config.Environment
uc *config.URLConfig

sshTries int
}

type Context interface {
Expand Down Expand Up @@ -91,9 +93,10 @@ func NewClient(ctx Context) (*Client, error) {
commandCredHelper: &commandCredentialHelper{
SkipPrompt: osEnv.Bool("GIT_TERMINAL_PROMPT", false),
},
gitEnv: gitEnv,
osEnv: osEnv,
uc: config.NewURLConfig(gitEnv),
gitEnv: gitEnv,
osEnv: osEnv,
uc: config.NewURLConfig(gitEnv),
sshTries: gitEnv.Int("lfs.ssh.retries", 5),
}

askpass, ok := osEnv.Get("GIT_ASKPASS")
Expand Down