diff --git a/cluster-autoscaler/cloudprovider/azure/azure_scale_set.go b/cluster-autoscaler/cloudprovider/azure/azure_scale_set.go index d746d4e0ad3..405b38bda98 100644 --- a/cluster-autoscaler/cloudprovider/azure/azure_scale_set.go +++ b/cluster-autoscaler/cloudprovider/azure/azure_scale_set.go @@ -215,12 +215,14 @@ func (scaleSet *ScaleSet) updateVMSSCapacity(size int64) { var isSuccess bool var err error + scaleSet.sizeMutex.Lock() + defer scaleSet.sizeMutex.Unlock() + defer func() { if err != nil { klog.Errorf("Failed to update the capacity for vmss %s with error %v, invalidate the cache so as to get the real size from API", scaleSet.Name, err) // Invalidate the VMSS size cache in order to fetch the size from the API. - scaleSet.sizeMutex.Lock() - defer scaleSet.sizeMutex.Unlock() + scaleSet.lastSizeRefresh = time.Now().Add(-1 * vmssSizeRefreshPeriod) } }()