From ab474fc212ef75691df56b449def21d48cd00321 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 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 0e87e6c813..abf931311c 100644 --- a/pkg/azureutils/azure_disk_utils.go +++ b/pkg/azureutils/azure_disk_utils.go @@ -26,7 +26,6 @@ import ( "regexp" "strconv" "strings" - "sync" "time" "unicode" @@ -102,8 +101,8 @@ var ( }, } - // lock mutex for RunPowerShellCommand - mutex = &sync.Mutex{} + // control the number of concurrent powershell commands running on Windows node + powershellCmdSem = make(chan struct{}, 3) ) type ManagedDiskParameters struct { @@ -854,9 +853,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...)