Skip to content

Commit 73aa71c

Browse files
authored
fix(cli): guard PowerShell process queries against exited PIDs (#3571)
## Summary `processIdentity` and `processParentPid` call `Get-CimInstance Win32_Process` to look up process metadata on Windows. When the target process has already exited, `Get-CimInstance` returns null and calling `.CreationDate.ToFileTimeUtc()` or `.ParentProcessId` on it throws `InvokeMethodOnNull`. The try/catch handles it, but PowerShell writes the error to stderr, which pollutes the test runner's output and causes spurious exit code 1 on Windows CI. Two fixes per call site: - Null-check the CimInstance before accessing properties (`$p = ...; if ($p) { $p.Property }`) - `-ErrorAction SilentlyContinue` + `stdio: ["pipe", "pipe", "ignore"]` to suppress any residual stderr Fixes the recurring `Tests on windows-latest` flake on main. ## Test plan - [x] All 196 CLI test files pass locally - [ ] Windows CI should no longer exit 1 from PowerShell stderr noise — Miga
1 parent f3099dc commit 73aa71c

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎packages/cli/src/utils/orphanCleanup.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ export function processIdentity(pid: number): string | null {
101101
"-NoProfile",
102102
"-NonInteractive",
103103
"-Command",
104-
`(Get-CimInstance Win32_Process -Filter 'ProcessId = ${pid}').CreationDate.ToFileTimeUtc()`,
104+
`$p = Get-CimInstance Win32_Process -Filter 'ProcessId = ${pid}' -ErrorAction SilentlyContinue; if ($p) { $p.CreationDate.ToFileTimeUtc() }`,
105105
],
106-
{ encoding: "utf8", timeout: 2000 },
106+
{ encoding: "utf8", timeout: 2000, stdio: ["pipe", "pipe", "ignore"] },
107107
).trim();
108108
return created ? `windows:${created}` : null;
109109
}
@@ -140,9 +140,9 @@ function processParentPid(pid: number): number | null {
140140
"-NoProfile",
141141
"-NonInteractive",
142142
"-Command",
143-
`(Get-CimInstance Win32_Process -Filter 'ProcessId = ${pid}').ParentProcessId`,
143+
`$p = Get-CimInstance Win32_Process -Filter 'ProcessId = ${pid}' -ErrorAction SilentlyContinue; if ($p) { $p.ParentProcessId }`,
144144
],
145-
{ encoding: "utf8", timeout: 2000 },
145+
{ encoding: "utf8", timeout: 2000, stdio: ["pipe", "pipe", "ignore"] },
146146
)
147147
: execFileSync("ps", ["-o", "ppid=", "-p", String(pid)], {
148148
encoding: "utf8",

0 commit comments

Comments
 (0)