wfaulk_bw
Contributor
Contributor

Creating new VM with async fails with "A task was canceled"

I am deploying a new VM from a content library OVA and it can take a while, so I am creating it with New-VM -RunAsync and then polling with Get-Task until it shows "Success" and then collecting the new VM with Wait-Task. However, sometimes the Wait-Task fails, returning $null and printing the error "A task was canceled", despite the vCenter task completing without issue.

My code is effectively:

$newvmtask = New-VM -RunAsync ...
do {
    Start-Sleep 15
    $taskstatus = Get-Task -Id $newvmtask.Uid
} while ($taskstatus.State -NE "Success")
$newvm = Wait-Task -Task $newvmtask

I've also tried it with the argument to Wait-Task as $taskstatus instead, but it produces the same problem.

Again, the problem is intermittent. It seems to coincide with the task completion taking over 5 minutes, which makes it feel like some sort of timeout. In fact, when I run New-VM without -RunAsync and it takes more than 5 minutes, I get the same error exactly 5 minutes after the cmdlet was submitted. But you'd think that using -RunAsync and polling would avoid that problem.

I'm having trouble consistently reproducing the problem, but in automated tasks it happens around half the time.

I have tried adjusting the client timeout with Set-PowerCLIConfiguration -Scope Session -WebOperationTimeoutSeconds 600 to extend the timeout to 10 minutes, but it doesn't seem to help.

This is running PowerCLI 13.0.0 under PowerShell 7.3.2 on Linux: CentOS 7.9.

Reply
0 Kudos