forked from mirror/redis
Merge pull request #49 from go-redis/fix/dont-leak-goroutines-when-sentinel-fails
sentinel: don't leak goroutines on sentinel fail. Fixes #48.
This commit is contained in:
commit
9805fc35f8
16
sentinel.go
16
sentinel.go
|
@ -157,9 +157,9 @@ func (d *sentinelFailover) MasterAddr() (string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, addr := range d.sentinelAddrs {
|
for i, sentinelAddr := range d.sentinelAddrs {
|
||||||
sentinel := newSentinel(&Options{
|
sentinel := newSentinel(&Options{
|
||||||
Addr: addr,
|
Addr: sentinelAddr,
|
||||||
|
|
||||||
DB: d.opt.DB,
|
DB: d.opt.DB,
|
||||||
Password: d.opt.Password,
|
Password: d.opt.Password,
|
||||||
|
@ -171,19 +171,21 @@ func (d *sentinelFailover) MasterAddr() (string, error) {
|
||||||
PoolSize: d.opt.PoolSize,
|
PoolSize: d.opt.PoolSize,
|
||||||
IdleTimeout: d.opt.IdleTimeout,
|
IdleTimeout: d.opt.IdleTimeout,
|
||||||
})
|
})
|
||||||
addr, err := sentinel.GetMasterAddrByName(d.masterName).Result()
|
masterAddr, err := sentinel.GetMasterAddrByName(d.masterName).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("redis-sentinel: GetMasterAddrByName %q failed: %s", d.masterName, err)
|
log.Printf("redis-sentinel: GetMasterAddrByName %q failed: %s", d.masterName, err)
|
||||||
} else {
|
sentinel.Close()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// Push working sentinel to the top.
|
// Push working sentinel to the top.
|
||||||
d.sentinelAddrs[0], d.sentinelAddrs[i] = d.sentinelAddrs[i], d.sentinelAddrs[0]
|
d.sentinelAddrs[0], d.sentinelAddrs[i] = d.sentinelAddrs[i], d.sentinelAddrs[0]
|
||||||
|
|
||||||
d.setSentinel(sentinel)
|
d.setSentinel(sentinel)
|
||||||
addr := net.JoinHostPort(addr[0], addr[1])
|
addr := net.JoinHostPort(masterAddr[0], masterAddr[1])
|
||||||
log.Printf("redis-sentinel: %q addr is %s", d.masterName, addr)
|
log.Printf("redis-sentinel: %q addr is %s", d.masterName, addr)
|
||||||
return addr, nil
|
return addr, nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return "", errors.New("redis: all sentinels are unreachable")
|
return "", errors.New("redis: all sentinels are unreachable")
|
||||||
}
|
}
|
||||||
|
@ -235,7 +237,7 @@ func (d *sentinelFailover) listen() {
|
||||||
msgIface, err := pubsub.Receive()
|
msgIface, err := pubsub.Receive()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("redis-sentinel: Receive failed: %s", err)
|
log.Printf("redis-sentinel: Receive failed: %s", err)
|
||||||
pubsub = nil
|
pubsub.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue