1
0
mirror of https://github.com/redis/go-redis.git synced 2025-09-05 20:24:00 +03:00

fix break of in dial

This commit is contained in:
Nedyalko Dyakov
2025-08-29 20:05:34 +03:00
parent b65bc6e591
commit 22e1d74d0d

View File

@@ -319,26 +319,22 @@ func (p *ConnPool) dialConn(ctx context.Context, pooled bool) (*Conn, error) {
const backoffDuration = 100 * time.Millisecond const backoffDuration = 100 * time.Millisecond
var lastErr error var lastErr error
for attempt := 0; attempt < maxRetries; attempt++ { shouldLoop := true
// Add backoff delay for retry attempts // when the timeout is reached, we should stop retrying
// (not for the first attempt, do at least one) // but keep the lastErr to return to the caller
if attempt > 0 { // instead of a generic context deadline exceeded error
select { for attempt := 0; (attempt < maxRetries) && shouldLoop; attempt++ {
case <-ctx.Done():
// we should have lastErr set, but just in case
if lastErr == nil {
lastErr = ctx.Err()
}
break
case <-time.After(backoffDuration):
// Continue with retry
}
}
netConn, err := p.cfg.Dialer(ctx) netConn, err := p.cfg.Dialer(ctx)
if err != nil { if err != nil {
lastErr = err lastErr = err
// Continue to next retry attempt // Add backoff delay for retry attempts
// (not for the first attempt, do at least one)
select {
case <-ctx.Done():
shouldLoop = false
case <-time.After(backoffDuration):
// Continue with retry
}
continue continue
} }