Skip to content

Commit 986a1f0

Browse files
CNS - fix locking in AssignDesiredIPConfigs (#2080)
moving lock to before accessing data it is supposed to protect Co-authored-by: rjdenney <[email protected]>
1 parent 24d77f1 commit 986a1f0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

cns/restserver/ipam.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,9 @@ func (service *HTTPRestService) GetExistingIPConfig(podInfo cns.PodInfo) ([]cns.
681681

682682
// Assigns a pod with all IPs desired
683683
func (service *HTTPRestService) AssignDesiredIPConfigs(podInfo cns.PodInfo, desiredIPAddresses []string) ([]cns.PodIpInfo, error) {
684+
service.Lock()
685+
defer service.Unlock()
686+
684687
// Gets the number of NCs which will determine the number of IPs given to a pod
685688
numOfNCs := len(service.state.ContainerStatus)
686689
// checks to make sure we have NCs before trying to get IPs
@@ -696,9 +699,6 @@ func (service *HTTPRestService) AssignDesiredIPConfigs(podInfo cns.PodInfo, desi
696699
// slice to keep track of IP configs to assign
697700
ipConfigsToAssign := make([]cns.IPConfigurationStatus, 0)
698701

699-
service.Lock()
700-
defer service.Unlock()
701-
702702
for _, desiredIP := range desiredIPAddresses {
703703
desiredIPMap[desiredIP] = struct{}{}
704704
}

0 commit comments

Comments
 (0)