Merge pull request #57591 from vikaschoudhary16/fix-race

Automatic merge from submit-queue (batch tested with PRs 57591, 57369). 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>.

Fix a race in the endpoint.go

**What this PR does / why we need it**:
This PR fixes a race in the endpoint.go

Fixes #56026


-->
```release-note
None
```

/sig node
/cc @RenaudWasTaken @ConnorDoyle @jiayingz @mindprince @ScorpioCPH @resouer @tengqm @vishh
This commit is contained in:
Kubernetes Submit Queue 2017-12-24 23:37:34 -08:00 committed by GitHub
commit 92e1028ac7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -164,7 +164,11 @@ func (e *endpointImpl) run() {
}
e.mutex.Lock()
e.devices = devices
// NOTE: Return a copy of 'devices' instead of returning a direct reference to local 'devices'
e.devices = make(map[string]pluginapi.Device)
for _, d := range devices {
e.devices[d.ID] = d
}
e.mutex.Unlock()
e.callback(e.resourceName, added, updated, deleted)