Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow more powershell command running at same time on Windows node #2699

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: allow more powershell command running at same time
fix

fix

fix
andyzhangx committed Dec 7, 2024
commit 85c248ce721a836017f31ccaad772f7871ba6d72
11 changes: 5 additions & 6 deletions pkg/azureutils/azure_disk_utils.go
Original file line number Diff line number Diff line change
@@ -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{}
// control 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...)