diff --git a/packages/subprocess/subprocess-local/tests/spawn.spec.ts b/packages/subprocess/subprocess-local/tests/spawn.spec.ts index 7d92447794..b9f0bf0321 100644 --- a/packages/subprocess/subprocess-local/tests/spawn.spec.ts +++ b/packages/subprocess/subprocess-local/tests/spawn.spec.ts @@ -60,7 +60,7 @@ function spec(command: string, overrides: SpecOverrides = {}) { } } -/** Poll until a pid no longer exists (kill(pid, 0) throws ESRCH). */ +/** Poll until a pid no longer exists, or is only a zombie on Linux. */ async function waitGone(pid: number, timeoutMs = 5_000): Promise { const deadline = Date.now() + timeoutMs while (Date.now() < deadline) { @@ -69,6 +69,16 @@ async function waitGone(pid: number, timeoutMs = 5_000): Promise { } catch { return } + if (process.platform === 'linux') { + try { + const stat = readFileSync(`/proc/${pid}/stat`, 'utf8') + const state = stat.slice(stat.lastIndexOf(')') + 2, stat.lastIndexOf(')') + 3) + if (state === 'Z' || state === 'X') return + } catch (error: unknown) { + if ((error as NodeJS.ErrnoException).code === 'ENOENT') return + throw error + } + } await new Promise(resolve => setTimeout(resolve, 20)) } throw new Error(`pid ${pid} still alive after ${timeoutMs}ms`)