Skip to content

Commit

Permalink
Retry completion on status 503 in the polling
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi committed Mar 7, 2024
1 parent 69d01af commit 3ef3772
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions artifactory/services/utils/multipartupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ func (mu *MultipartUpload) completeMultipartUpload(logMsgPrefix, sha1 string, mu
func (mu *MultipartUpload) status(logMsgPrefix string, multipartUploadClientWithNodeId *httputils.HttpClientDetails) (status statusResponse, err error) {
url := fmt.Sprintf("%s%sstatus", mu.artifactoryUrl, uploadsApi)
resp, body, err := mu.client.GetHttpClient().SendPost(url, []byte{}, *multipartUploadClientWithNodeId, logMsgPrefix)
// If the Artifactory node returns a "Service unavailable" error (status 503), attempt to retry the upload completion process on a different node.
if resp != nil && resp.StatusCode == http.StatusServiceUnavailable {
log.Warn(logMsgPrefix + fmt.Sprintf("The Artifactory node ID %s is unavailable. Trying to finalize the multipart upload process on a different node.", multipartUploadClientWithNodeId.Headers[routeToHeader]))
return statusResponse{Status: retryableError, Error: string(body)}, nil
}
if err != nil {
return
}
Expand Down
24 changes: 24 additions & 0 deletions artifactory/services/utils/multipartupload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,30 @@ func TestStatus(t *testing.T) {
assert.Equal(t, statusResponse{Status: finished, Progress: utils.Pointer(100)}, status)
}

func TestStatusServiceUnavailable(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Check method
assert.Equal(t, http.MethodPost, r.Method)

// Check URL
assert.Equal(t, "/api/v1/uploads/status", r.URL.Path)

// Send response 503 Service unavailable
w.WriteHeader(http.StatusServiceUnavailable)
_, err := w.Write([]byte("Service unavailable"))
assert.NoError(t, err)
})

// Create mock multipart upload with server
multipartUpload, cleanUp := createMockMultipartUpload(t, handler)
defer cleanUp()

// Execute status
status, err := multipartUpload.status("", &httputils.HttpClientDetails{})
assert.NoError(t, err)
assert.Equal(t, statusResponse{Status: retryableError, Error: "Service unavailable"}, status)
}

func TestAbort(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Check method
Expand Down

0 comments on commit 3ef3772

Please sign in to comment.