in spark/client/retry.go [154:188]
func wrapRetriableCall[Res rpcType](ctx context.Context, retryPolicies []RetryPolicy, in func(context.Context) (Res, error)) (Res, error) {
var lastErr error
var response Res
// Create the retry state for this wrapped call. The retry state captures the information about
// the wait time and how many retries to perform.
state := retryState{}
// As long as the error is retriable, we will retry the operation.
canRetry := true
for canRetry {
// Every loop iteration starts with being non-retriable.
canRetry = false
response, lastErr = in(ctx)
if lastErr != nil {
for _, h := range retryPolicies {
if h.Handler(lastErr) {
canRetry = true
wait := state.nextAttempt(h)
if wait != nil {
time.Sleep(*wait)
} else {
// If the retries are exceeded, simply return from here.
return nil, sparkerrors.WithType(lastErr, sparkerrors.RetriesExceeded)
}
// Breaks out of the retry handler loop.
break
}
}
} else {
// Exit loop if no error has been received.
return response, nil
}
}
// TODO: Should this simoly return the original error?
return nil, sparkerrors.WithType(lastErr, sparkerrors.RetriesExceeded)
}