System.Management.Automation · Engineering Report

Hosting API: Bounded Wait & Timeout

Two-phase fix replacing every unbounded WaitOne()/Wait() in the PowerShell hosting API with bounded alternatives, plus new opt-in public API for callers that need predictable failure modes.

8/8 Scenarios PASS 20 xUnit · 15 Pester Phase 1 + Phase 2 RFC pending
6
Source Files
+173
Lines Added
11
Requirements
8/8
Scenarios Pass
01

The Problem

Applications that embed PowerShell (services, hosts, plugins) have no way to bound how long the engine takes to respond. Six separate wait points could hang indefinitely:

Location Old code What hangs
PowerShell.Invoke()WaitOne()synchronous single-runspace invocation
pool.BeginGetRunspaceWaitOne()all RunspacePool slots occupied
BatchInvocationContextWait()multi-statement batch invocation
LocalPipeline.Stop()WaitOne()pipeline thread won't die
StopPipelines() (sequential)loop of Stop()N pipelines × unbounded stop time
LocalConnection.Close()WaitOne()runspace or job throttle close
Zero regression risk. All new timeout behaviour is opt-in. Any code that does not set PSInvocationSettings.Timeout or call Stop(TimeSpan) is byte-for-byte identical to the pre-fix code path — including the single-runspace Invoke() fast path which uses no Task.Run, no timer allocation, and runs on the same thread.