Skip to content

Commit

Permalink
Merge pull request PelicanPlatform#1101 from joereuss12/add-more-retr…
Browse files Browse the repository at this point in the history
…yable-errs-branch

Made additional retryable errors
  • Loading branch information
bbockelm authored Apr 13, 2024
2 parents d637eac + fb9dc53 commit eb07f39
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
11 changes: 11 additions & 0 deletions client/errorAccum.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func (te *TransferErrors) AddPastError(err error, timestamp time.Time) {
}
}

// This resets the TransferErrors object for testing purposes
func (te *TransferErrors) resetErrors() {
te.errors = make([]error, 0)
}

func (te *TransferErrors) Unwrap() []error {
return te.errors
}
Expand Down Expand Up @@ -134,6 +139,12 @@ func IsRetryable(err error) bool {
if errors.Is(err, config.MetadataTimeoutErr) {
return true
}
if errors.Is(err, &StoppedTransferError{}) {
return true
}
if errors.Is(err, &allocateMemoryError{}) {
return true
}
var cse *ConnectionSetupError
if errors.As(err, &cse) {
if sce, ok := cse.Unwrap().(grab.StatusCodeError); ok {
Expand Down
10 changes: 10 additions & 0 deletions client/errorAccum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,18 @@ func TestErrorsRetryableTrue(t *testing.T) {
// Try with a retryable error nested error
te.AddError(&url.Error{Err: &SlowTransferError{}})
assert.True(t, te.AllErrorsRetryable(), "ErrorsRetryable should be true")
te.resetErrors()

te.AddError(&ConnectionSetupError{})
assert.True(t, te.AllErrorsRetryable(), "ErrorsRetryable should be true")
te.resetErrors()

te.AddError(&StoppedTransferError{})
assert.True(t, te.AllErrorsRetryable(), "ErrorsRetryable should be true")
te.resetErrors()

te.AddError(&allocateMemoryError{})
assert.True(t, te.AllErrorsRetryable(), "ErrorsRetryable should be true")
te.resetErrors()

}
34 changes: 32 additions & 2 deletions client/handle_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ type (

// Error type for when the transfer started to return data then completely stopped
StoppedTransferError struct {
Err string
Err error
}

// SlowTransferError is an error that is returned when a transfer takes longer than the configured timeout
Expand All @@ -112,6 +112,10 @@ type (
Err error
}

allocateMemoryError struct {
Err error
}

// Transfer attempt error wraps an error with information about the service/proxy used
TransferAttemptError struct {
serviceHost string
Expand Down Expand Up @@ -303,9 +307,31 @@ func getProgressContainer() *mpb.Progress {
}

func (e *StoppedTransferError) Error() string {
return e.Err.Error()
}

func (e *StoppedTransferError) Unwrap() error {
return e.Err
}

func (e *StoppedTransferError) Is(target error) bool {
_, ok := target.(*StoppedTransferError)
return ok
}

func (e *allocateMemoryError) Error() string {
return e.Err.Error()
}

func (e *allocateMemoryError) Unwrap() error {
return e.Err
}

func (e *allocateMemoryError) Is(target error) bool {
_, ok := target.(*allocateMemoryError)
return ok
}

type HttpErrResp struct {
Code int
Err string
Expand Down Expand Up @@ -1701,12 +1727,16 @@ func downloadHTTP(ctx context.Context, te *TransferEngine, callback TransferCall
if resp.IsComplete() {
if err = resp.Err(); err != nil {
var sce grab.StatusCodeError
var cam syscall.Errno
if errors.Is(err, grab.ErrBadLength) {
err = fmt.Errorf("local copy of file is larger than remote copy %w", grab.ErrBadLength)
} else if errors.As(err, &sce) {
log.Debugln("Creating a client status code error")
sce2 := StatusCodeError(sce)
err = &sce2
} else if errors.As(err, &cam) && cam == syscall.ENOMEM {
// ENOMEM is error from os for unable to allocate memory
err = &allocateMemoryError{Err: err}
} else {
err = &ConnectionSetupError{Err: err}
}
Expand Down Expand Up @@ -1780,7 +1810,7 @@ Loop:
errMsg := "No progress for more than " + time.Since(noProgressStartTime).Truncate(time.Millisecond).String()
log.Errorln(errMsg)
err = &StoppedTransferError{
Err: errMsg,
Err: errors.New(errMsg),
}
return
}
Expand Down
1 change: 1 addition & 0 deletions client/handle_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ func TestStoppedTransfer(t *testing.T) {
// Make sure the errors are correct
assert.NotNil(t, err)
assert.IsType(t, &StoppedTransferError{}, err, err.Error())
assert.True(t, IsRetryable(err))
}

// Test connection error
Expand Down

0 comments on commit eb07f39

Please sign in to comment.