mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
Redis dialer: de-duplicate retry.WithBackoff() logic
This commit is contained in:
parent
5bcd5339b4
commit
e4e138aaa4
1 changed files with 5 additions and 14 deletions
|
|
@ -44,20 +44,11 @@ func (r *Redis) NewClient(logger *zap.SugaredLogger) (*icingaredis.Client, error
|
|||
func dial(ctx context.Context, network, addr string) (conn net.Conn, err error) {
|
||||
var dl net.Dialer
|
||||
|
||||
timeoutCtx, cancelTimeoutCtx := context.WithTimeout(ctx, 5*time.Minute)
|
||||
defer cancelTimeoutCtx()
|
||||
|
||||
_ = retry.WithBackoff(
|
||||
timeoutCtx,
|
||||
func(ctx context.Context) error {
|
||||
prevErr := err
|
||||
err = retry.WithBackoff(
|
||||
ctx,
|
||||
func(ctx context.Context) (err error) {
|
||||
conn, err = dl.DialContext(ctx, network, addr)
|
||||
|
||||
if prevErr != nil && errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {
|
||||
err = prevErr
|
||||
}
|
||||
|
||||
return err
|
||||
return
|
||||
},
|
||||
func(err error) bool {
|
||||
if op, ok := err.(*net.OpError); ok {
|
||||
|
|
@ -67,7 +58,7 @@ func dial(ctx context.Context, network, addr string) (conn net.Conn, err error)
|
|||
return false
|
||||
},
|
||||
backoff.NewExponentialWithJitter(1*time.Millisecond, 1*time.Second),
|
||||
0,
|
||||
5*time.Minute,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue