diff --git a/src/main/providers/windows-shell-preflight-runtime.windows.test.ts b/src/main/providers/windows-shell-preflight-runtime.windows.test.ts index 85512c40458..91f228b6e85 100644 --- a/src/main/providers/windows-shell-preflight-runtime.windows.test.ts +++ b/src/main/providers/windows-shell-preflight-runtime.windows.test.ts @@ -80,8 +80,12 @@ async function runPty(options: { proc.onData((data) => { output += data }) + let exited = false const exitPromise = new Promise((resolve) => { - proc.onExit(({ exitCode }) => resolve(exitCode)) + proc.onExit(({ exitCode }) => { + exited = true + resolve(exitCode) + }) }) let timeout: ReturnType | undefined const timeoutPromise = new Promise((_resolve, reject) => { @@ -102,10 +106,12 @@ async function runPty(options: { if (timeout) { clearTimeout(timeout) } - try { - proc.kill() - } catch { - // The PTY may already have exited. + if (!exited) { + try { + proc.kill() + } catch { + // The PTY may have exited while cleanup was starting. + } } } }