From 64dcf418488a26029291d322d5a2a452712e8047 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 fix --- pkg/azureutils/azure_disk_utils.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/azureutils/azure_disk_utils.go b/pkg/azureutils/azure_disk_utils.go index 62f0c2b022..d823237df8 100644 --- a/pkg/azureutils/azure_disk_utils.go +++ b/pkg/azureutils/azure_disk_utils.go @@ -25,7 +25,6 @@ import ( "regexp" "strconv" "strings" - "sync" "time" "unicode" @@ -88,8 +87,7 @@ var ( {Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER}, } - // lock mutex for RunPowerShellCommand - mutex = &sync.Mutex{} + sem = make(chan struct{}, 3) ) type ManagedDiskParameters struct { @@ -832,9 +830,9 @@ 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...)