Sentinel goroutine leak fixed (#1173)

Make sure to close the sentinel
This commit is contained in:
sobolevsv 2019-10-08 12:42:12 +03:00 committed by Vladimir Mihailenco
parent 17c058513b
commit 7f69d5e320
1 changed files with 11 additions and 7 deletions

View File

@ -245,7 +245,9 @@ func (c *sentinelFailover) MasterAddr() (string, error) {
}
func (c *sentinelFailover) masterAddr() (string, error) {
c.mu.RLock()
addr := c.getMasterAddr()
c.mu.RUnlock()
if addr != "" {
return addr, nil
}
@ -253,6 +255,15 @@ func (c *sentinelFailover) masterAddr() (string, error) {
c.mu.Lock()
defer c.mu.Unlock()
addr = c.getMasterAddr()
if addr != "" {
return addr, nil
}
if c.sentinel != nil {
c.closeSentinel()
}
for i, sentinelAddr := range c.sentinelAddrs {
sentinel := NewSentinelClient(&Options{
Addr: sentinelAddr,
@ -291,9 +302,7 @@ func (c *sentinelFailover) masterAddr() (string, error) {
}
func (c *sentinelFailover) getMasterAddr() string {
c.mu.RLock()
sentinel := c.sentinel
c.mu.RUnlock()
if sentinel == nil {
return ""
@ -303,11 +312,6 @@ func (c *sentinelFailover) getMasterAddr() string {
if err != nil {
internal.Logf("sentinel: GetMasterAddrByName name=%q failed: %s",
c.masterName, err)
c.mu.Lock()
if c.sentinel == sentinel {
c.closeSentinel()
}
c.mu.Unlock()
return ""
}