[GH-ISSUE #51] Wait-PveTaskIsFinish is extremely inefficient #31

Closed
opened 2026-02-26 17:32:14 +03:00 by kerem · 3 comments
Owner

Originally created by @r3st0r3 on GitHub (Feb 20, 2026).
Original GitHub issue: https://github.com/Corsinvest/cv4pve-api-powershell/issues/51

What happened?

The function Wait-PveTaskIsFinish uses a while-loop to wait for the finishing of a PVE-Task. It does so without using Start-Sleep. Instead it polls [DateTime]::Now every few milliseconds and checks if waittime until next API-Call is done yet. This leads to 100% cpu usage on the pwsh process used.

Expected behavior

You shoud use Start-Sleep to sleep (without heavy cpu-usage) between two while-loop-runs.

Relevant log output


Proxmox VE Version

9.1

Module Version

9.1.2

PowerShell Version

7.4.13

Version (working)

No response

On what operating system are you experiencing the issue?

Windows

Pull Request

  • I would like to do a Pull Request
Originally created by @r3st0r3 on GitHub (Feb 20, 2026). Original GitHub issue: https://github.com/Corsinvest/cv4pve-api-powershell/issues/51 ### What happened? The function Wait-PveTaskIsFinish uses a while-loop to wait for the finishing of a PVE-Task. It does so without using Start-Sleep. Instead it polls [DateTime]::Now every few milliseconds and checks if waittime until next API-Call is done yet. This leads to 100% cpu usage on the pwsh process used. ### Expected behavior You shoud use Start-Sleep to sleep (without heavy cpu-usage) between two while-loop-runs. ### Relevant log output ```shell ``` ### Proxmox VE Version 9.1 ### Module Version 9.1.2 ### PowerShell Version 7.4.13 ### Version (working) _No response_ ### On what operating system are you experiencing the issue? Windows ### Pull Request - [x] I would like to do a Pull Request
kerem closed this issue 2026-02-26 17:32:14 +03:00
Author
Owner

@r3st0r3 commented on GitHub (Feb 20, 2026):

See Pull Request #52

<!-- gh-comment-id:3933786706 --> @r3st0r3 commented on GitHub (Feb 20, 2026): See Pull Request #52
Author
Owner

@r3st0r3 commented on GitHub (Feb 20, 2026):

You could also include a Function showing a Powershell Progressbar while waiting for longer tasks (like moving a disk). I build a working example in my fork, could make a pull request for this also.

Examples:
Usage like Wait-PveTaskIsFinish without extra parameters (using defaults)

$DiskMove = New-PveNodesQemuMoveDisk -PveTicket $myCluster -node 'xyzpve17' -vmid 102 -disk scsi2 -storage 'PVE-01' -delete $true
if ($DiskMove.StatusCode -eq 200 -AND $DiskMove.IsSuccessStatusCode -eq $true) {
    Wait-PveTaskIsFinishedWithProgress -Upid $DiskMove.Response.data -Wait 2000 -Timeout $(5*60*1000)
}
Image

Usage with extra parameters

$DiskMove = New-PveNodesQemuMoveDisk -PveTicket $myCluster -node 'xyzpve17' -vmid 102 -disk scsi2 -storage 'PVE-01' -delete $true
if ($DiskMove.StatusCode -eq 200 -AND $DiskMove.IsSuccessStatusCode -eq $true) {
    Wait-PveTaskIsFinishedWithProgress -PveTicket $myCluster -Upid $DiskMove.Response.data -Wait 2000 -Timeout $(5*60*1000) -ProgressActivityText "Moving Disk from x to y" -ProgressStatusText "zZzZz..."
}
Image
<!-- gh-comment-id:3934437057 --> @r3st0r3 commented on GitHub (Feb 20, 2026): You could also include a Function showing a Powershell Progressbar while waiting for longer tasks (like moving a disk). I build a working example [in my fork](https://github.com/Corsinvest/cv4pve-api-powershell/commit/8f4145f6994db9eb404f273e84026139355717ad), could make a pull request for this also. **Examples:** Usage like Wait-PveTaskIsFinish without extra parameters (using defaults) ```powershell $DiskMove = New-PveNodesQemuMoveDisk -PveTicket $myCluster -node 'xyzpve17' -vmid 102 -disk scsi2 -storage 'PVE-01' -delete $true if ($DiskMove.StatusCode -eq 200 -AND $DiskMove.IsSuccessStatusCode -eq $true) { Wait-PveTaskIsFinishedWithProgress -Upid $DiskMove.Response.data -Wait 2000 -Timeout $(5*60*1000) } ``` <img width="1087" height="24" alt="Image" src="https://github.com/user-attachments/assets/6c981204-1161-4379-b903-4d267b59ab2c" /> Usage with extra parameters ```powershell $DiskMove = New-PveNodesQemuMoveDisk -PveTicket $myCluster -node 'xyzpve17' -vmid 102 -disk scsi2 -storage 'PVE-01' -delete $true if ($DiskMove.StatusCode -eq 200 -AND $DiskMove.IsSuccessStatusCode -eq $true) { Wait-PveTaskIsFinishedWithProgress -PveTicket $myCluster -Upid $DiskMove.Response.data -Wait 2000 -Timeout $(5*60*1000) -ProgressActivityText "Moving Disk from x to y" -ProgressStatusText "zZzZz..." } ``` <img width="1094" height="30" alt="Image" src="https://github.com/user-attachments/assets/1fcf5692-e2f5-4897-a03e-fc753e0f071d" />
Author
Owner

@franklupo commented on GitHub (Feb 24, 2026):

Fixed in v9.1.2! 🎉

Thanks to @r3st0r3 for both reporting the issue and submitting the fix via PR #52.

Changes included in v9.1.2:

  • Wait-PveTaskIsFinish: replaced the busy-wait loop with Start-Sleep to eliminate 100% CPU usage
  • Wait-PveTaskIsFinish: fixed timeout calculation using TotalMilliseconds instead of Milliseconds
  • New function Wait-PveTaskIsFinishedWithProgress: same fix plus a PowerShell progress bar while waiting

You can update with:

Update-Module -Name Corsinvest.ProxmoxVE.Api
<!-- gh-comment-id:3953809018 --> @franklupo commented on GitHub (Feb 24, 2026): Fixed in v9.1.2! 🎉 Thanks to @r3st0r3 for both reporting the issue and submitting the fix via PR #52. Changes included in v9.1.2: - `Wait-PveTaskIsFinish`: replaced the busy-wait loop with `Start-Sleep` to eliminate 100% CPU usage - `Wait-PveTaskIsFinish`: fixed timeout calculation using `TotalMilliseconds` instead of `Milliseconds` - New function `Wait-PveTaskIsFinishedWithProgress`: same fix plus a PowerShell progress bar while waiting You can update with: ```powershell Update-Module -Name Corsinvest.ProxmoxVE.Api ```
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/cv4pve-api-powershell#31
No description provided.