[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:
Zoltán Papp
2026-03-31 16:49:41 +02:00
parent 11e9c052b4
commit e9007f7191

View File

@@ -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
}