From af5b7a61448d9f00aebfaf3aa19373a861c9c13d Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Fri, 6 Dec 2024 15:00:54 +0000 Subject: [PATCH] fix: allow more powershell command running at same time --- pkg/azureutils/azure_disk_utils.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/azureutils/azure_disk_utils.go b/pkg/azureutils/azure_disk_utils.go index 62f0c2b022..8d482e80f6 100644 --- a/pkg/azureutils/azure_disk_utils.go +++ b/pkg/azureutils/azure_disk_utils.go @@ -88,8 +88,8 @@ var ( {Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER}, } - // lock mutex for RunPowerShellCommand - mutex = &sync.Mutex{} + wg sync.WaitGroup + sem = make(chan struct{}, 3) ) type ManagedDiskParameters struct { @@ -832,14 +832,18 @@ func SetKeyValueInMap(m map[string]string, key, value string) { } func RunPowershellCmd(command string, envs ...string) ([]byte, error) { - // only one powershell command can be executed at a time to avoid OOM - mutex.Lock() - defer mutex.Unlock() + // acquire a semaphore to limit the number of concurrent operations + sem <- struct{}{} + defer func() { <-sem }() cmd := exec.Command("powershell", "-Mta", "-NoProfile", "-Command", command) cmd.Env = append(os.Environ(), envs...) klog.V(6).Infof("Executing command: %q", cmd.String()) - return cmd.CombinedOutput() + output, err := cmd.CombinedOutput() + + // signal the completion of the operation + wg.Done() + return output, err } // GenerateVolumeName returns a PV name with clusterName prefix. The function