Skip to content

Commit

Permalink
Fix issue with stale clientConn
Browse files Browse the repository at this point in the history
The tranport does not check if the IP address of a node
has changed and returns the connection created with outdated info.
This happens in environments with dynamic IPs such a docker
and Kubernetes.
This fix adds an additional check to ensure the the target IP is up
to date.
  • Loading branch information
Zaccaria committed Jul 17, 2024
1 parent 023483e commit 41c703d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions raftapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ func (r raftAPI) getPeer(id raft.ServerID, target raft.ServerAddress) (pb.RaftTr
c.mtx.Lock()
}
defer c.mtx.Unlock()

if c.clientConn != nil && c.clientConn.Target() != string(target) {
err := c.clientConn.Close()
if err != nil {
return nil, err
}
c.clientConn = nil
}

if c.clientConn == nil {
conn, err := grpc.Dial(string(target), r.manager.dialOptions...)
if err != nil {
Expand Down

0 comments on commit 41c703d

Please sign in to comment.