From 9f31449b2088fc081c7ddb164d0238ba63fc9d0a 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 fix --- pkg/azureutils/azure_disk_utils.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/azureutils/azure_disk_utils.go b/pkg/azureutils/azure_disk_utils.go index 62f0c2b022..995c41e7dd 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,8 @@ var ( {Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER}, } - // lock mutex for RunPowerShellCommand - mutex = &sync.Mutex{} + // controlls the number of concurrent powershell commands running on Windows node + powershellCmdSem = make(chan struct{}, 3) ) type ManagedDiskParameters struct { @@ -832,9 +831,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 + powershellCmdSem <- struct{}{} + defer func() { <-powershellCmdSem }() cmd := exec.Command("powershell", "-Mta", "-NoProfile", "-Command", command) cmd.Env = append(os.Environ(), envs...)