Skip to content

Commit

Permalink
fix: panic on cluster redirection to the same host (#641)
Browse files Browse the repository at this point in the history
Signed-off-by: Rueian <[email protected]>
  • Loading branch information
rueian committed Sep 21, 2024
1 parent 6188b89 commit 6306a24
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,18 +389,18 @@ func (c *clusterClient) pick(ctx context.Context, slot uint16, toReplica bool) (
return p, nil
}

func (c *clusterClient) redirectOrNew(addr string, prev conn, slot uint16, mode RedirectMode) (p conn) {
func (c *clusterClient) redirectOrNew(addr string, prev conn, slot uint16, mode RedirectMode) conn {
c.mu.RLock()
cc := c.conns[addr]
c.mu.RUnlock()
if cc.conn != nil && prev != cc.conn {
return cc.conn
}
c.mu.Lock()

if cc = c.conns[addr]; cc.conn == nil {
p = c.connFn(addr, c.opt)
c.conns[addr] = connrole{conn: p, replica: false}
p := c.connFn(addr, c.opt)
cc = connrole{conn: p, replica: false}
c.conns[addr] = cc
if mode == RedirectMove {
c.pslots[slot] = p
}
Expand All @@ -412,9 +412,9 @@ func (c *clusterClient) redirectOrNew(addr string, prev conn, slot uint16, mode
time.Sleep(time.Second * 5)
prev.Close()
}(prev)
p = c.connFn(addr, c.opt)
c.conns[addr] = connrole{conn: p, replica: cc.replica}

p := c.connFn(addr, c.opt)
cc = connrole{conn: p, replica: cc.replica}
c.conns[addr] = cc
if mode == RedirectMove {
if cc.replica {
c.rslots[slot] = p
Expand All @@ -424,7 +424,7 @@ func (c *clusterClient) redirectOrNew(addr string, prev conn, slot uint16, mode
}
}
c.mu.Unlock()
return p
return cc.conn
}

func (c *clusterClient) B() Builder {
Expand Down

0 comments on commit 6306a24

Please sign in to comment.