Skip to content

Commit

Permalink
fix: allow more powershell command running at same time
Browse files Browse the repository at this point in the history
fix

fix
  • Loading branch information
andyzhangx committed Dec 7, 2024
1 parent ad7f51a commit 9f31449
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{}
// controlls the number of concurrent powershell commands running on Windows node

Check failure on line 90 in pkg/azureutils/azure_disk_utils.go

View workflow job for this annotation

GitHub Actions / Check for spelling errors

controlls ==> controls

Check failure on line 90 in pkg/azureutils/azure_disk_utils.go

View workflow job for this annotation

GitHub Actions / Go Lint

`controlls` is a misspelling of `controls` (misspell)
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 9f31449

Please sign in to comment.