Skip to content

Commit

Permalink
Merge pull request #2711 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…2699-to-release-1.29

[release-1.29] fix: allow more powershell command running at same time on Windows node
  • Loading branch information
andyzhangx authored Dec 11, 2024
2 parents 828e709 + ab474fc commit 6a57a11
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/azureutils/azure_disk_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"regexp"
"strconv"
"strings"
"sync"
"time"
"unicode"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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...)
Expand Down

0 comments on commit 6a57a11

Please sign in to comment.