Clean up Windows smoke relay shutdown

This commit is contained in:
Mohamed Boudra
2026-03-10 20:22:07 +07:00
parent e1f4e6fafb
commit 6b4978b428
2 changed files with 43 additions and 1 deletions

View File

@@ -443,6 +443,7 @@ jobs:
exit 1
- name: Smoke check managed runtime for Windows
timeout-minutes: 12
env:
PASEO_MANAGED_SMOKE_SKIP_BUILD: "1"
run: npm run smoke:managed-daemon --workspace=@getpaseo/desktop

View File

@@ -110,6 +110,19 @@ function escapeForRegExp(value) {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
async function waitForChildExit(child, timeoutMs) {
if (!child || child.exitCode !== null || child.killed) {
return;
}
await new Promise((resolve) => {
const timeout = setTimeout(resolve, timeoutMs);
child.once("exit", () => {
clearTimeout(timeout);
resolve();
});
});
}
async function execFileWithTimeout(command, args, options, label) {
try {
return await execFileAsync(command, args, {
@@ -141,6 +154,34 @@ async function runBinary(binaryPath, args, env) {
};
}
async function terminateChildProcess(child, label) {
if (!child || child.exitCode !== null || child.killed) {
return;
}
if (process.platform === "win32" && typeof child.pid === "number") {
try {
await execFileWithTimeout(
"taskkill",
["/pid", String(child.pid), "/T", "/F"],
{ maxBuffer: 1024 * 1024 },
`${label} taskkill`
);
} catch {}
await waitForChildExit(child, 5_000);
return;
}
try {
child.kill("SIGTERM");
} catch {}
await waitForChildExit(child, 5_000);
if (child.exitCode === null && !child.killed) {
try {
child.kill("SIGKILL");
} catch {}
await waitForChildExit(child, 5_000);
}
}
async function runWorkspaceCli(args, env) {
const { stdout, stderr } = await execFileWithTimeout(
process.execPath,
@@ -808,6 +849,6 @@ try {
}
} catch {}
try {
relayProcess?.kill("SIGTERM");
await terminateChildProcess(relayProcess, "local relay");
} catch {}
}