Adjusting the logic around the returned error from the retry function

This commit is contained in:
Scott Finlay 2016-11-07 17:39:05 +01:00
parent c6737ac64c
commit a6812ba332
2 changed files with 16 additions and 4 deletions

View File

@ -2,9 +2,10 @@ package client
import "golang.org/x/net/context"
// note that returning either true or a non-nil error will result in the call not being retried
type RetryFunc func(ctx context.Context, req Request, retryCount int, err error) (bool, error)
// always retry on error
func alwaysRetry(ctx context.Context, req Request, retryCount int, err error) (bool, error) {
return true, err
return true, nil
}

View File

@ -300,10 +300,16 @@ func (r *rpcClient) Call(ctx context.Context, request Request, response interfac
return nil
}
if retry, err := callOpts.Retry(ctx, request, i, err); !retry {
retry, rerr := callOpts.Retry(ctx, request, i, err)
if rerr != nil {
return rerr
}
if !retry {
return err
}
gerr = err
}
}
@ -406,8 +412,13 @@ func (r *rpcClient) Stream(ctx context.Context, request Request, opts ...CallOpt
return rsp.stream, nil
}
if retry, err := callOpts.Retry(ctx, request, i, rsp.err); !retry {
return nil, err
retry, rerr := callOpts.Retry(ctx, request, i, rsp.err)
if rerr != nil {
return nil, rerr
}
if !retry {
return nil, rsp.err
}
grr = err