mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-12-24 16:57:27 +00:00
Fix a data race in TopologyCache
The member variable `cpuRatiosByZone` should be accessed with the lock acquired as it could be be updated by `SetNodes` concurrently. Signed-off-by: Quan Tian <qtian@vmware.com> Co-authored-by: Antonio Ojea <aojea@google.com>
This commit is contained in:
@@ -270,6 +270,9 @@ func (t *TopologyCache) HasPopulatedHints(serviceKey string) bool {
|
||||
// it is not possible to provide allocations that are below the overload
|
||||
// threshold, a nil value will be returned.
|
||||
func (t *TopologyCache) getAllocations(numEndpoints int) (map[string]Allocation, *EventBuilder) {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
|
||||
// it is similar to checking !t.sufficientNodeInfo
|
||||
if t.cpuRatiosByZone == nil {
|
||||
return nil, &EventBuilder{
|
||||
@@ -293,9 +296,6 @@ func (t *TopologyCache) getAllocations(numEndpoints int) (map[string]Allocation,
|
||||
}
|
||||
}
|
||||
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
|
||||
remainingMinEndpoints := numEndpoints
|
||||
minTotal := 0
|
||||
allocations := map[string]Allocation{}
|
||||
|
||||
Reference in New Issue
Block a user