MCPcopy Create free account
hub / github.com/erpc/erpc / runRetry

Method runRetry

data/cache_executor.go:111–148  ·  view source on GitHub ↗
(
	ctx context.Context,
	hedged func(ctx context.Context) ([]byte, error),
)

Source from the content-addressed store, hash-verified

109}
110
111func (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
150func (e *cacheExecutor) runHedgeBytes(
151 ctx context.Context,

Callers 1

RunBytesMethod · 0.95

Calls 5

ComputeBackoffFunction · 0.92
SleepCtxFunction · 0.92
execStateFromCtxFunction · 0.85
isTransportErrorFunction · 0.85
AddMethod · 0.65

Tested by

no test coverage detected