MCPcopy
hub / github.com/lima-vm/lima / getOrCreateClient

Method getOrCreateClient

pkg/hostagent/hostagent.go:857–876  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

855}
856
857func (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
878func (a *HostAgent) createConnection(ctx context.Context) (net.Conn, error) {
879 conn, _, err := a.driver.GuestAgentConn(ctx)

Callers 3

syncTimeOnceMethod · 0.95
watchGuestAgentEventsMethod · 0.95
startInotifyMethod · 0.95

Calls 4

LockMethod · 0.80
UnlockMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected