Skip to content

Commit

Permalink
Fix CLI cancellation on windows (#1393)
Browse files Browse the repository at this point in the history
Aborting the signal does not work on windows, spawn a `taskkill` process
on windows instead.
  • Loading branch information
ilia-db authored Oct 17, 2024
1 parent ab1125b commit 9c864af
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/databricks-vscode/src/cli/CliWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ async function runBundleCommand(

logger?.debug(quote([cmd, ...args]), {bundleOpName});
const abortController = new AbortController();
cancellationToken?.onCancellationRequested(() => abortController.abort());
let options: SpawnOptionsWithoutStdio = {
cwd: workspaceFolder.fsPath,
env: removeUndefinedKeys(env),
Expand All @@ -237,6 +236,15 @@ async function runBundleCommand(
({cmd, args, options} = getEscapedCommandAndAgrs(cmd, args, options));
try {
const p = spawn(cmd, args, options);
cancellationToken?.onCancellationRequested(() => {
if (process.platform === "win32" && p.pid) {
// On windows aborting the signal doesn't kill the CLI.
// Use taskkill here with the "force" and "tree" flags (to kill sub-processes too)
spawn("taskkill", ["/pid", String(p.pid), "/T", "/F"]);
} else {
abortController.abort();
}
});
const {stdout, stderr} = await waitForProcess(p, onStdOut, onStdError);
logger?.info(displayLogs.end, {
bundleOpName,
Expand Down

0 comments on commit 9c864af

Please sign in to comment.