wslc: assert Pid > 0 in DockerExecProcessControl::SetPid (#40567)

Defense-in-depth follow-up to PR #40550. The exec polling loop in WSLCContainerImpl::Exec now correctly filters Pid > 0 before calling SetPid, but a future caller that bypassed that check would silently hang the process wait (because Docker never emits exec_die for a process that never spawned). Assert at the lowest level so any such regression fires loudly in Debug builds. Suggested by @OneBlue in the PR #40550 review. Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Ben Hillis committed May 15, 2026 at 17:19 UTC 96b0912913c0fb600b03f6ab218b9d3a0204534d
1 file changed +6
src/windows/wslcsession/WSLCProcessControl.cpp
+6
@@ -151,6 +151,12 @@ void DockerExecProcessControl::SetPid(int Pid)
151 {
152 std::lock_guard lock{m_lock};
153
154 + // Pid must be a real (forked) process. Docker reports Pid=0 in the brief
155 + // window between StartExec returning and runc actually forking the user
156 + // process; treating 0 as a valid PID causes the exec wait to hang forever
157 + // because Docker never emits exec_die for a process that never spawned
158 + // (see PR #40550). Callers must filter Pid > 0 themselves.
159 + WI_ASSERT(Pid > 0);
160 WI_ASSERT(!m_pid.has_value());
161
162 m_pid = Pid;