Product: PowerShell Universal
Version: 5.6.12
Summary
We experienced intermittent API failures in PowerShell Universal where API endpoints would return HTTP 400 and log a System.ArgumentOutOfRangeException during runspace creation. The exception is thrown inside PowerShell Universal (UDRunspaceFactory.GetRunspace()), before any endpoint script code is executed.
The issue was resolved by changing SessionTimeout from 0 (infinite) to a positive integer (e.g., 60 minutes).
Symptoms
-
Some requests succeed, but periodically requests fail with:
-
HTTP 400
-
Error log:
System.ArgumentOutOfRangeException: The added or subtracted value results in an un-representable DateTime. (Parameter 'value') -
The failure happens before the endpoint code starts executing.
Stack Trace (excerpt)
System.ArgumentOutOfRangeException: The added or subtracted value results in an un-representable DateTime. (Parameter 'value')
at System.DateTime.ThrowDateArithmetic(Int32 param)
at System.DateTime.AddMinutes(Double value)
at UniversalDashboard.Services.UDRunspaceFactory.GetRunspace() in ...\UDRunspaceFactory.cs:line 37
at UniversalAutomation.Host.PowerShellApiService.ExecuteRequest(ApiRequest request) in ...\ApiService.cs:line 171
Configuration that triggers the issue
In .universal/settings.ps1:
$Parameters = @{
# ...
SessionTimeout = 0
# ...
}
Set-PSUSetting @Parameters
Expected behavior
-
SessionTimeout = 0(“no limit / infinite”) should not cause API failures. -
Runspace creation should be stable and should not throw
ArgumentOutOfRangeException.
Actual behavior
-
With
SessionTimeout = 0, PowerShell Universal intermittently fails to create a runspace. -
PSU internally calls
DateTime.AddMinutes(...)(seen in stack trace) and triggers aDateTimeoverflow (ArgumentOutOfRangeException). -
Endpoint execution is aborted and the API returns HTTP 400.
Workaround / Fix
Changing SessionTimeout to a positive value resolves the issue:
$Parameters = @{
# ...
SessionTimeout = 60
# ...
}
Set-PSUSetting @Parameters
After this change:
-
The intermittent
ArgumentOutOfRangeExceptionstopped occurring. -
API endpoints became stable again.
Why this appears to be a platform bug
-
The stack trace points entirely to PowerShell Universal internals (
UDRunspaceFactory.GetRunspace()), not to endpoint scripts. -
The failure occurs before the endpoint code runs, suggesting a runspace/session housekeeping edge-case.
-
Even if
SessionTimeout=0is considered a special value, the platform should handle it gracefully and not crash during runspace creation.
Request
Please:
-
Confirm whether
SessionTimeout = 0is a supported configuration. -
Investigate and fix the
DateTime.AddMinutesoverflow inUDRunspaceFactory.GetRunspace()whenSessionTimeout=0. -
Provide recommended configuration guidance if
0should not be used.