vSphere Cloud Provider: avoid read race during logout

The Client nil check was added in 6d1c4a3 , but there was not any
go test coverage of that code path until e22f9ca

Fixes #65696
This commit is contained in:
Doug MacEachern 2018-07-06 10:05:03 -07:00
parent 91b729342d
commit 9a219513dc
2 changed files with 9 additions and 5 deletions

View File

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

View File

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