diff --git a/pkg/cloudprovider/providers/vsphere/vclib/connection.go b/pkg/cloudprovider/providers/vsphere/vclib/connection.go index 63d2cdbdff1..379b68df088 100644 --- a/pkg/cloudprovider/providers/vsphere/vclib/connection.go +++ b/pkg/cloudprovider/providers/vsphere/vclib/connection.go @@ -131,7 +131,14 @@ func (connection *VSphereConnection) login(ctx context.Context, client *vim25.Cl // Logout calls SessionManager.Logout for the given connection. func (connection *VSphereConnection) Logout(ctx context.Context) { - m := session.NewManager(connection.Client) + clientLock.Lock() + c := connection.Client + clientLock.Unlock() + if c == nil { + return + } + + m := session.NewManager(c) hasActiveSession, err := m.SessionIsActive(ctx) if err != nil { diff --git a/pkg/cloudprovider/providers/vsphere/vsphere.go b/pkg/cloudprovider/providers/vsphere/vsphere.go index 421b2bd302c..62a9cfb2e88 100644 --- a/pkg/cloudprovider/providers/vsphere/vsphere.go +++ b/pkg/cloudprovider/providers/vsphere/vsphere.go @@ -510,11 +510,8 @@ func buildVSphereFromConfig(cfg VSphereConfig) (*VSphere, error) { func logout(vs *VSphere) { for _, vsphereIns := range vs.vsphereInstanceMap { - if vsphereIns.conn.Client != nil { - vsphereIns.conn.Logout(context.TODO()) - } + vsphereIns.conn.Logout(context.TODO()) } - } // Instances returns an implementation of Instances for vSphere.