Skip to content

Commit

Permalink
Sentinel goroutine leak fixed (redis#1173)
Browse files Browse the repository at this point in the history
Make sure to close the sentinel
  • Loading branch information
sobolevsv authored and vmihailenco committed Oct 8, 2019
1 parent 17c0585 commit 7f69d5e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,25 @@ 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
}

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,
Expand Down Expand Up @@ -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 ""
Expand All @@ -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 ""
}

Expand Down

0 comments on commit 7f69d5e

Please sign in to comment.