Skip to content

Commit

Permalink
Do not attempt to kill the process if it has already exited (#22424)
Browse files Browse the repository at this point in the history
Closes #22420

This bugs seems to have existed every since `rawProcessApi.ts` was
created. `proc.killed` can be `false` even after process has exited.
  • Loading branch information
Kartik Raj authored Nov 7, 2023
1 parent f6cfa6e commit 7bc45e5
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/client/common/process/rawProcessApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -114,7 +125,8 @@ export function plainExec(
const deferred = createDeferred<ExecutionResult<string>>();
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 {
Expand Down

0 comments on commit 7bc45e5

Please sign in to comment.