mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-23 22:43:38 -04:00
[client] Fix connection swap to properly close old gRPC connection
Close the old `gRPC.ClientConn` after successfully swapping to a new connection during reconnection.
This commit is contained in:
@@ -154,21 +154,20 @@ func (c *GRPCClient) recreateConnection() error {
|
||||
return backoff.Permanent(ErrClientClosed)
|
||||
}
|
||||
|
||||
defer func(conn *grpc.ClientConn) {
|
||||
_ = conn.Close()
|
||||
}(c.clientConn)
|
||||
|
||||
conn, err := grpc.NewClient(c.clientConn.Target(), c.opts...)
|
||||
if err != nil {
|
||||
c.mu.Unlock()
|
||||
return fmt.Errorf("create new connection: %w", err)
|
||||
}
|
||||
|
||||
old := c.clientConn
|
||||
c.clientConn = conn
|
||||
c.realClient = proto.NewFlowServiceClient(conn)
|
||||
c.stream = nil
|
||||
c.mu.Unlock()
|
||||
|
||||
_ = old.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user