( ctx context.Context, hedged func(ctx context.Context) ([]byte, error), )
| 109 | } |
| 110 | |
| 111 | func (e *cacheExecutor) runRetry( |
| 112 | ctx context.Context, |
| 113 | hedged func(ctx context.Context) ([]byte, error), |
| 114 | ) ([]byte, error) { |
| 115 | maxAttempts := 1 |
| 116 | if e.cfg != nil && e.cfg.Retry != nil && e.cfg.Retry.MaxAttempts > 0 { |
| 117 | maxAttempts = e.cfg.Retry.MaxAttempts |
| 118 | } |
| 119 | startTime := time.Now() |
| 120 | |
| 121 | var lastErr error |
| 122 | for attempt := 0; attempt < maxAttempts; attempt++ { |
| 123 | if st := execStateFromCtx(ctx); st != nil { |
| 124 | st.CacheAttempts.Add(1) |
| 125 | if attempt > 0 { |
| 126 | st.CacheRetries.Add(1) |
| 127 | } |
| 128 | } |
| 129 | data, err := hedged(ctx) |
| 130 | if err == nil || !isTransportError(err) { |
| 131 | return data, err |
| 132 | } |
| 133 | lastErr = err |
| 134 | |
| 135 | if attempt < maxAttempts-1 { |
| 136 | d := failsafe.ComputeBackoff(e.cfg.Retry, attempt) |
| 137 | if d > 0 { |
| 138 | if serr := failsafe.SleepCtx(ctx, d); serr != nil { |
| 139 | return nil, serr |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | if lastErr != nil { |
| 145 | return nil, common.NewErrFailsafeRetryExceeded(scopeConnector, lastErr, &startTime) |
| 146 | } |
| 147 | return nil, nil |
| 148 | } |
| 149 | |
| 150 | func (e *cacheExecutor) runHedgeBytes( |
| 151 | ctx context.Context, |
no test coverage detected