Failed to get runspace

Every 1 or 2 days, Powershell Universal hangs.
In older versions, it would just hang, without any response, but in the current version, all users get the error message “Failed to get runspace.”.

Is there any way to prevent this?

Product: PowerShell Universal
Version: 3.4.1

I also raised an issue on GitHub:

@adam It would be awesome of you could shine your light on this one. Thanks!

I had the same issue, it was due to the number of runspaces avaliable and the queueing involved. I increased the runspaces to 250 and i have never seen a problem since. You can do this under ‘Settings’ ‘Environments’ and select the env you are using, then edit and set ‘Max Runspaces’ to whatever you like (obviously this is going to incresase resources, so keep it as low as possible).

Or via code (Repository.universal\environments.ps1:
New-PSUEnvironment -Name “Integrated” -Version “7.2.0” -Path “Universal.Server” -Modules @() -Variables @(‘*’) -PSModulePath @() -MaxRunspaces 250

Thanks Neo!
I tried it right after you posted about that, and Adam as well on Github.
It seems to be running stable now. It is weird though, because when I look, at the processes stat on the dashboard, it rarely gets above 15.
And, when I got the “Failed to get runspace” error, it never seemed to recover until I restarted PSU. So it seems like sometimes a runspace becomes invalid or something, and then is blocked.

Anyway, I’ll keep monitoring it for now.

1 Like