4
4
"context"
5
5
"crypto/tls"
6
6
"errors"
7
+ "fmt"
7
8
"net"
8
9
"strings"
9
10
"sync"
@@ -583,17 +584,12 @@ func (c *sentinelFailover) MasterAddr(ctx context.Context) (string, error) {
583
584
sentinelCli := NewSentinelClient (c .opt .sentinelOptions (addr ))
584
585
addrVal , err := sentinelCli .GetMasterAddrByName (ctx , c .opt .MasterName ).Result ()
585
586
if err != nil {
586
- if errors .Is (err , context .Canceled ) || errors .Is (err , context .DeadlineExceeded ) {
587
- // Report immediately and return
588
- errCh <- err
589
- return
590
- }
591
587
internal .Logger .Printf (ctx , "sentinel: GetMasterAddrByName addr=%s, master=%q failed: %s" ,
592
588
addr , c .opt .MasterName , err )
593
589
_ = sentinelCli .Close ()
590
+ errCh <- err
594
591
return
595
592
}
596
-
597
593
once .Do (func () {
598
594
masterAddr = net .JoinHostPort (addrVal [0 ], addrVal [1 ])
599
595
// Push working sentinel to the top
@@ -605,21 +601,15 @@ func (c *sentinelFailover) MasterAddr(ctx context.Context) (string, error) {
605
601
}(i , sentinelAddr )
606
602
}
607
603
608
- done := make (chan struct {})
609
- go func () {
610
- wg .Wait ()
611
- close (done )
612
- }()
613
-
614
- select {
615
- case <- done :
616
- if masterAddr != "" {
617
- return masterAddr , nil
618
- }
619
- return "" , errors .New ("redis: all sentinels specified in configuration are unreachable" )
620
- case err := <- errCh :
621
- return "" , err
604
+ wg .Wait ()
605
+ if masterAddr != "" {
606
+ return masterAddr , nil
607
+ }
608
+ errs := make ([]error , len (c .sentinelAddrs ))
609
+ for err := range errCh {
610
+ errs = append (errs , err )
622
611
}
612
+ return "" , fmt .Errorf ("redis: all sentinels specified in configuration are unreachable: %w" , errs )
623
613
}
624
614
625
615
func (c * sentinelFailover ) replicaAddrs (ctx context.Context , useDisconnected bool ) ([]string , error ) {
0 commit comments