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

fix(api): for retry on timeout with service #5784

Merged
merged 2 commits into from
Mar 31, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions engine/api/services/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ func (s *defaultServiceClient) DoJSONRequest(ctx context.Context, method, path s
func doJSONRequest(ctx context.Context, srvs []sdk.Service, method, path string, in interface{}, out interface{}, mods ...cdsclient.RequestModifier) (http.Header, int, error) {
var lastErr = sdk.WithStack(errors.New("unable to call service: service not found"))
var lastCode int
for attempt := 0; attempt < 5; attempt++ {
var attempts int64
for attempts = 0; attempts < 5; attempts++ {
for i := range srvs {
srv := &srvs[i]
headers, code, err := _doJSONRequest(ctx, srv, method, path, in, out, mods...)
Expand All @@ -162,7 +163,7 @@ func doJSONRequest(ctx context.Context, srvs []sdk.Service, method, path string,
}
}

log.Error(ctx, "unable to call service: maximum attempt exceed : %+v", lastErr)
log.Error(ctx, "unable to call service: maximum attempt exceed: %+v lastCode:%d attempts:%d", lastErr, lastCode, attempts)
return nil, lastCode, sdk.WithStack(lastErr)
}

Expand Down Expand Up @@ -305,7 +306,10 @@ func doRequestFromURL(ctx context.Context, method string, callURL *url.URL, read
//Do the request
resp, err := HTTPClient.Do(req)
if err != nil {
return nil, nil, 0, sdk.WrapError(err, "request failed")
if resp != nil && resp.StatusCode > 0 {
return nil, nil, resp.StatusCode, sdk.WrapError(err, "request failed with resp status code: %d", resp.StatusCode)
}
return nil, nil, 500, sdk.WrapError(err, "request failed - use code 500")
}
defer resp.Body.Close()

Expand All @@ -327,5 +331,5 @@ func doRequestFromURL(ctx context.Context, method string, callURL *url.URL, read
return nil, resp.Header, resp.StatusCode, cdserr
}

return nil, resp.Header, resp.StatusCode, sdk.WithStack(fmt.Errorf("request failed"))
return nil, resp.Header, resp.StatusCode, sdk.WithStack(fmt.Errorf("request failed with status code: %d", resp.StatusCode))
}
1 change: 1 addition & 0 deletions engine/vcs/bitbucketserver/client_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (b *bitbucketClient) Branches(ctx context.Context, fullname string) ([]sdk.

return branches, nil
}

func (b *bitbucketClient) Branch(ctx context.Context, fullname string, filter string) (*sdk.VCSBranch, error) {
t := strings.Split(fullname, "/")
if len(t) != 2 {
Expand Down