Skip to content

Commit 7bc45e5

Browse files
author
Kartik Raj
authored
Do not attempt to kill the process if it has already exited (#22424)
Closes #22420 This bugs seems to have existed every since `rawProcessApi.ts` was created. `proc.killed` can be `false` even after process has exited.
1 parent f6cfa6e commit 7bc45e5

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/client/common/process/rawProcessApis.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,21 @@ export function shellExec(
7575
resolve({ stderr: stderr && stderr.length > 0 ? stderr : undefined, stdout });
7676
}
7777
};
78+
let procExited = false;
7879
const proc = exec(command, shellOptions, callback); // NOSONAR
80+
proc.once('close', () => {
81+
procExited = true;
82+
});
83+
proc.once('exit', () => {
84+
procExited = true;
85+
});
86+
proc.once('error', () => {
87+
procExited = true;
88+
});
7989
const disposable: IDisposable = {
8090
dispose: () => {
81-
if (!proc.killed) {
91+
// If process has not exited nor killed, force kill it.
92+
if (!procExited && !proc.killed) {
8293
if (proc.pid) {
8394
killPid(proc.pid);
8495
} else {
@@ -114,7 +125,8 @@ export function plainExec(
114125
const deferred = createDeferred<ExecutionResult<string>>();
115126
const disposable: IDisposable = {
116127
dispose: () => {
117-
if (!proc.killed) {
128+
// If process has not exited nor killed, force kill it.
129+
if (!proc.killed && !deferred.completed) {
118130
if (proc.pid) {
119131
killPid(proc.pid);
120132
} else {

0 commit comments

Comments
 (0)