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(worker): improve error message + fix retry on cdnDownloadItem #5838

Merged
merged 6 commits into from
Jun 9, 2021
Merged
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
18 changes: 12 additions & 6 deletions engine/worker/cmd_cache.go
Original file line number Diff line number Diff line change
@@ -144,10 +144,13 @@ func cachePushCmd() func(cmd *cobra.Command, args []string) {
if resp.StatusCode >= 300 {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
sdk.Exit("cache push HTTP error %v", err)
sdk.Exit("cache push HTTP %d error %v", resp.StatusCode, err)
}
cdsError := sdk.DecodeError(body)
sdk.Exit("Error: http code %d : %v", resp.StatusCode, cdsError)
var sdkErr sdk.Error
if json.Unmarshal(body, &sdkErr); err != nil {
sdk.Exit("unable to read error: %s: %v", string(body), err)
}
sdk.Exit("%v", sdkErr)
}

fmt.Printf("Worker cache push with success (tag: %s)\n", args[0])
@@ -230,10 +233,13 @@ func cachePullCmd() func(cmd *cobra.Command, args []string) {
if resp.StatusCode >= 300 {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
sdk.Exit("cache pull HTTP error %v", err)
sdk.Exit("cache pull HTTP %d error %v", resp.StatusCode, err)
}
var sdkErr sdk.Error
if json.Unmarshal(body, &sdkErr); err != nil {
sdk.Exit("unable to read error: %s: %v", string(body), err)
}
cdsError := sdk.DecodeError(body)
sdk.Exit("Error: %v", cdsError)
sdk.Exit("%v", sdkErr)
}

fmt.Printf("Worker cache pull with success (tag: %s)\n", args[0])
2 changes: 1 addition & 1 deletion engine/worker/internal/handler_cache.go
Original file line number Diff line number Diff line change
@@ -211,7 +211,7 @@ func cachePullHandler(ctx context.Context, wk *CurrentWorker) http.HandlerFunc {
r, err = wk.client.CDNItemDownload(ctx, wk.cdnHttpAddr, items.Items[0].APIRefHash, sdk.CDNTypeItemWorkerCache)
if err != nil {
err = sdk.Error{
Message: "worker cache pull > Cannot pull cache: " + err.Error(),
Message: "Cannot pull cache: " + err.Error(),
Status: http.StatusNotFound,
}
log.Error(ctx, "%v", err)
15 changes: 11 additions & 4 deletions sdk/cdsclient/client_cdn.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package cdsclient

import (
"context"
"encoding/json"
"fmt"
"io"
"io/ioutil"
@@ -18,16 +19,22 @@ func (c *client) CDNItemDownload(ctx context.Context, cdnAddr string, hash strin
auth := "Bearer " + c.config.SessionToken
req.Header.Add("Authorization", auth)
})
if err != nil {
return nil, err
}
if code >= 400 {
var stringBody string
if reader != nil {
body, _ := ioutil.ReadAll(reader)
if err := sdk.DecodeError(body); err != nil {
return nil, err
var errSdk sdk.Error
if err := json.Unmarshal(body, &errSdk); err == nil && errSdk.Message != "" {
stringBody = errSdk.Error()
}
if stringBody == "" {
stringBody = string(body)
}
stringBody = string(body)
}
return nil, newAPIError(fmt.Errorf("HTTP %d: %s", code, stringBody))
return nil, newAPIError(fmt.Errorf("%s", stringBody))
}
return reader, err
}
9 changes: 1 addition & 8 deletions sdk/cdsclient/http.go
Original file line number Diff line number Diff line change
@@ -301,18 +301,11 @@ func (c *client) Stream(ctx context.Context, httpClient HTTPClient, method strin
c.config.SessionToken = ""
}

if resp.StatusCode == 409 || resp.StatusCode > 500 {
if resp.StatusCode == 409 || resp.StatusCode >= 500 {
time.Sleep(250 * time.Millisecond)
savederror = extractBodyErrorFromResponse(resp)
continue
}

// if no request error by status > 500, check CDS error
// if there is a CDS errors, return it
if resp.StatusCode == 500 {
return nil, resp.Header, resp.StatusCode, extractBodyErrorFromResponse(resp)
}

return resp.Body, resp.Header, resp.StatusCode, nil
}

1 change: 0 additions & 1 deletion sdk/error.go
Original file line number Diff line number Diff line change
@@ -719,7 +719,6 @@ func ExtractHTTPError(source error) Error {
if httpError.Message == "" {
httpError.Message = httpError.Translate()
}

return httpError
}