Skip to content

Commit a192b2e

Browse files
committed
fix(windows): resolve taskkill in core spawns
1 parent 7975ec0 commit a192b2e

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

‎src/cli/update-cli/update-command.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ import {
100100
type PreUpdateConfigRestoreInput,
101101
} from "../../infra/update-post-core-context.js";
102102
import { runGatewayUpdate, type UpdateRunResult } from "../../infra/update-runner.js";
103+
import { getWindowsSystem32ExePath } from "../../infra/windows-install-roots.js";
103104
import { normalizePluginsConfig, resolveEffectiveEnableState } from "../../plugins/config-state.js";
104105
import {
105106
loadInstalledPluginIndexInstallRecords,
@@ -2877,10 +2878,14 @@ async function readPostCorePluginUpdateResultFile(
28772878
function stopPostCoreUpdateChild(child: ChildProcess): void {
28782879
if (process.platform === "win32" && child.pid) {
28792880
try {
2880-
const killer = spawn("taskkill", ["/PID", String(child.pid), "/T", "/F"], {
2881-
stdio: "ignore",
2882-
windowsHide: true,
2883-
});
2881+
const killer = spawn(
2882+
getWindowsSystem32ExePath("taskkill.exe"),
2883+
["/PID", String(child.pid), "/T", "/F"],
2884+
{
2885+
stdio: "ignore",
2886+
windowsHide: true,
2887+
},
2888+
);
28842889
killer.once("error", () => {
28852890
child.kill();
28862891
});

‎src/process/exec.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
decodeWindowsOutputBuffer,
1212
resolveWindowsConsoleEncoding,
1313
} from "../infra/windows-encoding.js";
14+
import { getWindowsSystem32ExePath } from "../infra/windows-install-roots.js";
1415
import { logDebug, logError } from "../logger.js";
1516
import { killProcessTree as terminateProcessTree } from "./kill-tree.js";
1617
import { resolveCommandStdio } from "./spawn-utils.js";
@@ -430,8 +431,9 @@ export async function runCommandWithTimeout(
430431
}
431432
if (killProcessTree && typeof child.pid === "number" && child.pid > 0) {
432433
if (process.platform === "win32") {
434+
const taskkillPath = getWindowsSystem32ExePath("taskkill.exe");
433435
try {
434-
spawn("taskkill", ["/PID", String(child.pid), "/T"], {
436+
spawn(taskkillPath, ["/PID", String(child.pid), "/T"], {
435437
stdio: "ignore",
436438
windowsHide: true,
437439
});
@@ -447,7 +449,7 @@ export async function runCommandWithTimeout(
447449
return;
448450
}
449451
try {
450-
spawn("taskkill", ["/PID", String(child.pid), "/T", "/F"], {
452+
spawn(taskkillPath, ["/PID", String(child.pid), "/T", "/F"], {
451453
stdio: "ignore",
452454
windowsHide: true,
453455
});
@@ -467,10 +469,14 @@ export async function runCommandWithTimeout(
467469
}
468470
if (process.platform === "win32" && typeof child.pid === "number" && child.pid > 0) {
469471
try {
470-
spawn("taskkill", ["/PID", String(child.pid), "/T", "/F"], {
471-
stdio: "ignore",
472-
windowsHide: true,
473-
});
472+
spawn(
473+
getWindowsSystem32ExePath("taskkill.exe"),
474+
["/PID", String(child.pid), "/T", "/F"],
475+
{
476+
stdio: "ignore",
477+
windowsHide: true,
478+
},
479+
);
474480
return;
475481
} catch {
476482
// Fall through to Node's direct child kill as a last resort.

‎src/process/exec.windows.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vite
77
import {
88
resetWindowsInstallRootsForTests,
99
getWindowsInstallRoots,
10+
getWindowsSystem32ExePath,
1011
} from "../infra/windows-install-roots.js";
1112
import { withMockedWindowsPlatform, withRestoredMocks } from "../test-utils/vitest-spies.js";
1213

@@ -496,7 +497,7 @@ describe("windows command wrapper behavior", () => {
496497
expect(child.kill).not.toHaveBeenCalled();
497498
expect(spawnMock).toHaveBeenCalledTimes(2);
498499
const taskkillCall = requireSpawnCall(1);
499-
expect(taskkillCall[0]).toBe("taskkill");
500+
expect(taskkillCall[0]).toBe(getWindowsSystem32ExePath("taskkill.exe"));
500501
expect(taskkillCall[1]).toEqual(["/PID", "1234", "/T", "/F"]);
501502
expect(taskkillCall[2]).toEqual({
502503
stdio: "ignore",

0 commit comments

Comments
 (0)