Merge pull request #65913 from dougm/vcp-logout-race

Automatic merge from submit-queue (batch tested with PRs 65946, 65904, 65913, 65906, 65920). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

vSphere Cloud Provider: avoid read race during logout

**What this PR does / why we need it**:

The `go test -race` will sometimes detect a read race in the vSphere Cloud Provider logout function, causing tests to fail.

**Which issue(s) this PR fixes**:
Fixes #65696

**Special notes for your reviewer**:

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

**Release note**:

```release-note
none
```
pull/8/head
Kubernetes Submit Queue 2018-07-07 16:25:11 -07:00 committed by GitHub
commit c899ccf441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.