From 9c864af4a1ea6ed1b14136d6af195b6d8a2af5ad Mon Sep 17 00:00:00 2001 From: Ilia Babanov Date: Thu, 17 Oct 2024 13:02:41 +0200 Subject: [PATCH] Fix CLI cancellation on windows (#1393) Aborting the signal does not work on windows, spawn a `taskkill` process on windows instead. --- packages/databricks-vscode/src/cli/CliWrapper.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/databricks-vscode/src/cli/CliWrapper.ts b/packages/databricks-vscode/src/cli/CliWrapper.ts index cf83fdfe6..50aa329af 100644 --- a/packages/databricks-vscode/src/cli/CliWrapper.ts +++ b/packages/databricks-vscode/src/cli/CliWrapper.ts @@ -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), @@ -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,