From 7bc45e57253b89b28cd5c7eaa9197ac70ef42b7f Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 7 Nov 2023 10:56:24 -0800 Subject: [PATCH] Do not attempt to kill the process if it has already exited (#22424) Closes https://github.com/microsoft/vscode-python/issues/22420 This bugs seems to have existed every since `rawProcessApi.ts` was created. `proc.killed` can be `false` even after process has exited. --- src/client/common/process/rawProcessApis.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/client/common/process/rawProcessApis.ts b/src/client/common/process/rawProcessApis.ts index 1e1b742a031c..27cd88d42851 100644 --- a/src/client/common/process/rawProcessApis.ts +++ b/src/client/common/process/rawProcessApis.ts @@ -75,10 +75,21 @@ export function shellExec( resolve({ stderr: stderr && stderr.length > 0 ? stderr : undefined, stdout }); } }; + let procExited = false; const proc = exec(command, shellOptions, callback); // NOSONAR + proc.once('close', () => { + procExited = true; + }); + proc.once('exit', () => { + procExited = true; + }); + proc.once('error', () => { + procExited = true; + }); const disposable: IDisposable = { dispose: () => { - if (!proc.killed) { + // If process has not exited nor killed, force kill it. + if (!procExited && !proc.killed) { if (proc.pid) { killPid(proc.pid); } else { @@ -114,7 +125,8 @@ export function plainExec( const deferred = createDeferred>(); const disposable: IDisposable = { dispose: () => { - if (!proc.killed) { + // If process has not exited nor killed, force kill it. + if (!proc.killed && !deferred.completed) { if (proc.pid) { killPid(proc.pid); } else {