(ctx context.Context)
| 855 | } |
| 856 | |
| 857 | func (a *HostAgent) getOrCreateClient(ctx context.Context) (*guestagentclient.GuestAgentClient, error) { |
| 858 | a.clientMu.Lock() |
| 859 | defer a.clientMu.Unlock() |
| 860 | if a.client != nil && isGuestAgentSocketAccessible(ctx, a.client) { |
| 861 | return a.client, nil |
| 862 | } |
| 863 | // The previous client (if any) is unreachable: close its underlying gRPC |
| 864 | // ClientConn before replacing it, otherwise the resolver/transport |
| 865 | // goroutines and the dialed net.Conn (e.g. forwarded ga.sock) leak across |
| 866 | // every guest agent restart or VM reboot. |
| 867 | if a.client != nil { |
| 868 | if err := a.client.Close(); err != nil { |
| 869 | logrus.WithError(err).Debug("failed to close stale guest agent client") |
| 870 | } |
| 871 | a.client = nil |
| 872 | } |
| 873 | var err error |
| 874 | a.client, err = guestagentclient.NewGuestAgentClient(a.createConnection) |
| 875 | return a.client, err |
| 876 | } |
| 877 | |
| 878 | func (a *HostAgent) createConnection(ctx context.Context) (net.Conn, error) { |
| 879 | conn, _, err := a.driver.GuestAgentConn(ctx) |
no test coverage detected