From d1f94a05c00608b77fb2dee3ec9e88c2d9ecc57f Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Sun, 9 Jan 2022 22:29:13 +0800 Subject: [PATCH 1/6] Use taskkill for win32 --- package.json | 1 - src/util.ts | 9 +++++++-- yarn.lock | 5 ----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index d6ea62381..3eb9c1650 100644 --- a/package.json +++ b/package.json @@ -1726,7 +1726,6 @@ "node-fetch": "^2.6.1", "popper.js": "^1.16.1", "showdown": "^1.9.1", - "tree-kill": "^1.2.2", "vscode-languageclient": "^7.0.0", "vsls": "^1.0.4753", "winreg": "^1.2.4", diff --git a/src/util.ts b/src/util.ts index 638365ee7..c9cba047d 100644 --- a/src/util.ts +++ b/src/util.ts @@ -8,7 +8,6 @@ import * as vscode from 'vscode'; import * as cp from 'child_process'; import { rGuestService, isGuestSession } from './liveShare'; import { extensionContext } from './extension'; -import * as kill from 'tree-kill'; export function config(): vscode.WorkspaceConfiguration { return vscode.workspace.getConfiguration('r'); @@ -421,7 +420,13 @@ export function exec(command: string, args?: ReadonlyArray, options?: cp const disposable = asDisposable(proc, () => { if (running) { if (process.platform === 'win32') { - kill(proc.pid); + cp.exec(`taskkill /PID ${proc.pid} /T /F`, (error, stdout, stderr) => { + console.log('taskkill stdout: ' + stdout); + console.log('taskkill stderr: ' + stderr); + if (error) { + console.log('error: ' + error.message); + } + }); } else { proc.kill('SIGKILL'); } diff --git a/yarn.lock b/yarn.lock index 8e9baca73..84bc1965b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2597,11 +2597,6 @@ to-regex-range@^5.0.1: resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.3.9.tgz#717b8f220cc0bb7b44e40514c22b2e8bbc70d8b9" integrity sha1-cXuPIgzAu3tE5AUUwisui7xw2Lk= -tree-kill@^1.2.2: - version "1.2.2" - resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc" - integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A== - ts-loader@^9.2.3: version "9.2.3" resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-9.2.3.tgz#dc3b6362a4d4382493cd4f138d345f419656de68" From 1737b14541cc4d8155d8a8c90e3420b739ff749a Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Mon, 10 Jan 2022 15:50:32 +0000 Subject: [PATCH 2/6] Use spawn + taskkill in windows --- src/util.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/util.ts b/src/util.ts index c9cba047d..e37bea037 100644 --- a/src/util.ts +++ b/src/util.ts @@ -420,13 +420,7 @@ export function exec(command: string, args?: ReadonlyArray, options?: cp const disposable = asDisposable(proc, () => { if (running) { if (process.platform === 'win32') { - cp.exec(`taskkill /PID ${proc.pid} /T /F`, (error, stdout, stderr) => { - console.log('taskkill stdout: ' + stdout); - console.log('taskkill stderr: ' + stderr); - if (error) { - console.log('error: ' + error.message); - } - }); + cp.spawn('taskkill', ['/pid', String(proc.pid), '/f', '/t']); } else { proc.kill('SIGKILL'); } From 4df9e1765702b976163797d812e5ae5d5abbe9d9 Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Tue, 11 Jan 2022 06:20:43 +0000 Subject: [PATCH 3/6] Revert to using tree-kill --- package.json | 1 + src/util.ts | 3 ++- yarn.lock | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 3eb9c1650..d6ea62381 100644 --- a/package.json +++ b/package.json @@ -1726,6 +1726,7 @@ "node-fetch": "^2.6.1", "popper.js": "^1.16.1", "showdown": "^1.9.1", + "tree-kill": "^1.2.2", "vscode-languageclient": "^7.0.0", "vsls": "^1.0.4753", "winreg": "^1.2.4", diff --git a/src/util.ts b/src/util.ts index e37bea037..638365ee7 100644 --- a/src/util.ts +++ b/src/util.ts @@ -8,6 +8,7 @@ import * as vscode from 'vscode'; import * as cp from 'child_process'; import { rGuestService, isGuestSession } from './liveShare'; import { extensionContext } from './extension'; +import * as kill from 'tree-kill'; export function config(): vscode.WorkspaceConfiguration { return vscode.workspace.getConfiguration('r'); @@ -420,7 +421,7 @@ export function exec(command: string, args?: ReadonlyArray, options?: cp const disposable = asDisposable(proc, () => { if (running) { if (process.platform === 'win32') { - cp.spawn('taskkill', ['/pid', String(proc.pid), '/f', '/t']); + kill(proc.pid); } else { proc.kill('SIGKILL'); } diff --git a/yarn.lock b/yarn.lock index 84bc1965b..8e9baca73 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2597,6 +2597,11 @@ to-regex-range@^5.0.1: resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.3.9.tgz#717b8f220cc0bb7b44e40514c22b2e8bbc70d8b9" integrity sha1-cXuPIgzAu3tE5AUUwisui7xw2Lk= +tree-kill@^1.2.2: + version "1.2.2" + resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc" + integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A== + ts-loader@^9.2.3: version "9.2.3" resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-9.2.3.tgz#dc3b6362a4d4382493cd4f138d345f419656de68" From 0a4c75ae916670722944fd75fef221c994ea60c8 Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Wed, 12 Jan 2022 08:07:45 +0000 Subject: [PATCH 4/6] Use taskkill --- src/util.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util.ts b/src/util.ts index 638365ee7..02fb14a79 100644 --- a/src/util.ts +++ b/src/util.ts @@ -412,16 +412,19 @@ export function asDisposable(toDispose: T, disposeFunction: (...args: unknown export type DisposableProcess = cp.ChildProcessWithoutNullStreams & vscode.Disposable; export function exec(command: string, args?: ReadonlyArray, options?: cp.CommonOptions, onDisposed?: () => unknown): DisposableProcess { const proc = cp.spawn(command, args, options); + console.log(`Process ${proc.pid} spawned`); let running = true; const exitHandler = () => { running = false; + console.log(`Process ${proc.pid} exited`); }; proc.on('exit', exitHandler); proc.on('error', exitHandler); const disposable = asDisposable(proc, () => { if (running) { + console.log(`Process ${proc.pid} terminating`); if (process.platform === 'win32') { - kill(proc.pid); + cp.spawn('taskkill', ['/pid', proc.pid.toString(), '/f', '/t']); } else { proc.kill('SIGKILL'); } From 2b78757872a363b94dc5b5d7b449c1aa8e7f1c88 Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Wed, 12 Jan 2022 08:25:07 +0000 Subject: [PATCH 5/6] Remove tree-kill --- package.json | 1 - src/util.ts | 1 - yarn.lock | 5 ----- 3 files changed, 7 deletions(-) diff --git a/package.json b/package.json index d6ea62381..3eb9c1650 100644 --- a/package.json +++ b/package.json @@ -1726,7 +1726,6 @@ "node-fetch": "^2.6.1", "popper.js": "^1.16.1", "showdown": "^1.9.1", - "tree-kill": "^1.2.2", "vscode-languageclient": "^7.0.0", "vsls": "^1.0.4753", "winreg": "^1.2.4", diff --git a/src/util.ts b/src/util.ts index 02fb14a79..af6fea6dd 100644 --- a/src/util.ts +++ b/src/util.ts @@ -8,7 +8,6 @@ import * as vscode from 'vscode'; import * as cp from 'child_process'; import { rGuestService, isGuestSession } from './liveShare'; import { extensionContext } from './extension'; -import * as kill from 'tree-kill'; export function config(): vscode.WorkspaceConfiguration { return vscode.workspace.getConfiguration('r'); diff --git a/yarn.lock b/yarn.lock index 8e9baca73..84bc1965b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2597,11 +2597,6 @@ to-regex-range@^5.0.1: resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.3.9.tgz#717b8f220cc0bb7b44e40514c22b2e8bbc70d8b9" integrity sha1-cXuPIgzAu3tE5AUUwisui7xw2Lk= -tree-kill@^1.2.2: - version "1.2.2" - resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc" - integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A== - ts-loader@^9.2.3: version "9.2.3" resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-9.2.3.tgz#dc3b6362a4d4382493cd4f138d345f419656de68" From 8586c1c9c607b71821d230c18ba6ee7bf624210f Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Sat, 15 Jan 2022 21:06:56 +0800 Subject: [PATCH 6/6] Use spawnSync --- src/util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.ts b/src/util.ts index af6fea6dd..4b5546139 100644 --- a/src/util.ts +++ b/src/util.ts @@ -423,7 +423,7 @@ export function exec(command: string, args?: ReadonlyArray, options?: cp if (running) { console.log(`Process ${proc.pid} terminating`); if (process.platform === 'win32') { - cp.spawn('taskkill', ['/pid', proc.pid.toString(), '/f', '/t']); + cp.spawnSync('taskkill', ['/pid', proc.pid.toString(), '/f', '/t']); } else { proc.kill('SIGKILL'); }