Start-Job on Windows Server 2016 hangs Powershell
Start-Job seems to sometimes cause the calling thread to hang. If you create a loop in ISE and spin off a bunch of jobs, inevitably it will hang. This has only been tested using a ScriptBlock.
As a workaround, you can use threads to do the heavy lifting and so if they fail to start the job, just recreate the thread.

3 comments
-
Aaron Kincer commented
This seems to be fixed after recent testing. Not sure which update fixed it.
-
Aaron Kincer commented
Using process explorer, I discovered that if I kill the sub-process that was spun up when it hung the parent thread takes off again. So it looks like it's happening during the spinning up of the Powershell instance it's creating.
Also -- I'm not really able to recreate this on a Windows 2008 box with WMF 5.1 installed. The Powershell versions are slightly different though, so not sure if there's a bug fix for this between versions or if it's completely specific to 2016.
WMF 5.1 2008 PS Version -- 5.1.14409.1005
WMF 5.1 2016 PS Version -- 5.1.14393.3053 -
Aaron Kincer commented
Here's a code block that I can run and reliably have Powershell stop. It never stops at the same place. Sometimes in the first few jobs and sometimes much later.
$ScriptBlock = {
$test = "blah"
}
$arguments = "Whatever args you want"
for ($j = 1; $j -lt 200; $j++)
{
Write-Host "Starting job $j"
Start-Job -Name "Job_$j" -ScriptBlock $ScriptBlock -ArgumentList $arguments
Write-Host "Finished starting job $j"
Start-Sleep 1
$jobs = Get-Job
while ($jobs.Count -ge 6)
{
Get-Job | Remove-Job
Start-Sleep 1
$jobs = Get-Job
}
}