Skip to content

Commit 9c864af

Browse files
authored
Fix CLI cancellation on windows (#1393)
Aborting the signal does not work on windows, spawn a `taskkill` process on windows instead.
1 parent ab1125b commit 9c864af

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/databricks-vscode/src/cli/CliWrapper.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ async function runBundleCommand(
227227

228228
logger?.debug(quote([cmd, ...args]), {bundleOpName});
229229
const abortController = new AbortController();
230-
cancellationToken?.onCancellationRequested(() => abortController.abort());
231230
let options: SpawnOptionsWithoutStdio = {
232231
cwd: workspaceFolder.fsPath,
233232
env: removeUndefinedKeys(env),
@@ -237,6 +236,15 @@ async function runBundleCommand(
237236
({cmd, args, options} = getEscapedCommandAndAgrs(cmd, args, options));
238237
try {
239238
const p = spawn(cmd, args, options);
239+
cancellationToken?.onCancellationRequested(() => {
240+
if (process.platform === "win32" && p.pid) {
241+
// On windows aborting the signal doesn't kill the CLI.
242+
// Use taskkill here with the "force" and "tree" flags (to kill sub-processes too)
243+
spawn("taskkill", ["/pid", String(p.pid), "/T", "/F"]);
244+
} else {
245+
abortController.abort();
246+
}
247+
});
240248
const {stdout, stderr} = await waitForProcess(p, onStdOut, onStdError);
241249
logger?.info(displayLogs.end, {
242250
bundleOpName,

0 commit comments

Comments
 (0)