Skip to content

Commit

Permalink
Merge pull request #2699 from andyzhangx/allow-more-powershell-comman…
Browse files Browse the repository at this point in the history
…d-running

fix: allow more powershell command running at same time on Windows node
  • Loading branch information
andyzhangx authored Dec 8, 2024
2 parents 5b8f284 + 85c248c commit a3c4f1a
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 @@ -25,7 +25,6 @@ import (
"regexp"
"strconv"
"strings"
"sync"
"time"
"unicode"

Expand Down Expand Up @@ -88,8 +87,8 @@ var (
{Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER},
}

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

0 comments on commit a3c4f1a

Please sign in to comment.