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
  • Loading branch information
andyzhangx committed Dec 6, 2024
1 parent ad7f51a commit af5b7a6
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/azureutils/azure_disk_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ var (
{Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER},
}

// lock mutex for RunPowerShellCommand
mutex = &sync.Mutex{}
wg sync.WaitGroup
sem = make(chan struct{}, 3)
)

type ManagedDiskParameters struct {
Expand Down Expand Up @@ -832,14 +832,18 @@ 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
sem <- struct{}{}
defer func() { <-sem }()

cmd := exec.Command("powershell", "-Mta", "-NoProfile", "-Command", command)
cmd.Env = append(os.Environ(), envs...)
klog.V(6).Infof("Executing command: %q", cmd.String())
return cmd.CombinedOutput()
output, err := cmd.CombinedOutput()

// signal the completion of the operation
wg.Done()
return output, err
}

// GenerateVolumeName returns a PV name with clusterName prefix. The function
Expand Down

0 comments on commit af5b7a6

Please sign in to comment.