Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"context"
"crypto/tls"
"errors"
"fmt"
"net"
"strings"
"sync"
Expand Down Expand Up @@ -583,17 +584,12 @@
sentinelCli := NewSentinelClient(c.opt.sentinelOptions(addr))
addrVal, err := sentinelCli.GetMasterAddrByName(ctx, c.opt.MasterName).Result()
if err != nil {
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
// Report immediately and return
errCh <- err
return
}
internal.Logger.Printf(ctx, "sentinel: GetMasterAddrByName addr=%s, master=%q failed: %s",
addr, c.opt.MasterName, err)
_ = sentinelCli.Close()
errCh <- err
return
}

once.Do(func() {
masterAddr = net.JoinHostPort(addrVal[0], addrVal[1])
// Push working sentinel to the top
Expand All @@ -605,21 +601,15 @@
}(i, sentinelAddr)
}

done := make(chan struct{})
go func() {
wg.Wait()
close(done)
}()

select {
case <-done:
if masterAddr != "" {
return masterAddr, nil
}
return "", errors.New("redis: all sentinels specified in configuration are unreachable")
case err := <-errCh:
return "", err
wg.Wait()
if masterAddr != "" {
return masterAddr, nil
}
errs := make([]error, len(c.sentinelAddrs))
for err := range errCh {
errs = append(errs, err)
}
return "", fmt.Errorf("redis: all sentinels specified in configuration are unreachable: %w", errs)

Check failure on line 612 in sentinel.go

View workflow job for this annotation

GitHub Actions / benchmark (8.0-RC1, 1.23.x)

fmt.Errorf format %w has arg errs of wrong type []error

Check failure on line 612 in sentinel.go

View workflow job for this annotation

GitHub Actions / build (1.24.x, 7.4.2-54)

fmt.Errorf format %w has arg errs of wrong type []error

Check failure on line 612 in sentinel.go

View workflow job for this annotation

GitHub Actions / test-redis-ce (8.0-RC1, 1.23.x)

fmt.Errorf format %w has arg errs of wrong type []error

Check failure on line 612 in sentinel.go

View workflow job for this annotation

GitHub Actions / test-redis-ce (8.0-RC1, 1.24.x)

fmt.Errorf format %w has arg errs of wrong type []error

Check failure on line 612 in sentinel.go

View workflow job for this annotation

GitHub Actions / benchmark (8.0-RC1, 1.24.x)

fmt.Errorf format %w has arg errs of wrong type []error

Check failure on line 612 in sentinel.go

View workflow job for this annotation

GitHub Actions / test-redis-ce (7.4.2, 1.23.x)

fmt.Errorf format %w has arg errs of wrong type []error

Check failure on line 612 in sentinel.go

View workflow job for this annotation

GitHub Actions / benchmark (7.4.2, 1.23.x)

fmt.Errorf format %w has arg errs of wrong type []error

Check failure on line 612 in sentinel.go

View workflow job for this annotation

GitHub Actions / test-redis-ce (7.4.2, 1.24.x)

fmt.Errorf format %w has arg errs of wrong type []error

Check failure on line 612 in sentinel.go

View workflow job for this annotation

GitHub Actions / benchmark (7.4.2, 1.24.x)

fmt.Errorf format %w has arg errs of wrong type []error

Check failure on line 612 in sentinel.go

View workflow job for this annotation

GitHub Actions / test-redis-ce (7.2.7, 1.23.x)

fmt.Errorf format %w has arg errs of wrong type []error

Check failure on line 612 in sentinel.go

View workflow job for this annotation

GitHub Actions / test-redis-ce (7.2.7, 1.24.x)

fmt.Errorf format %w has arg errs of wrong type []error
}

func (c *sentinelFailover) replicaAddrs(ctx context.Context, useDisconnected bool) ([]string, error) {
Expand Down
Loading