[testresolver] kill server on shutdown

This commit is contained in:
Martin Aeschlimann 2019-06-14 12:06:59 +02:00
parent bfa6a69e6b
commit 8c4a49f8b9
3 changed files with 53 additions and 3 deletions

View file

@ -0,0 +1,12 @@
#!/bin/bash
terminateTree() {
for cpid in $(/usr/bin/pgrep -P $1); do
terminateTree $cpid
done
kill -9 $1 > /dev/null 2>&1
}
for pid in $*; do
terminateTree $pid
done

View file

@ -10,6 +10,7 @@ import * as fs from 'fs';
import * as os from 'os';
import * as net from 'net';
import { downloadAndUnzipVSCodeServer } from './download';
import { terminateProcess } from './util/processes';
let extHostProcess: cp.ChildProcess | undefined;
const enum CharCode {
@ -87,14 +88,14 @@ export function activate(context: vscode.ExtensionContext) {
if (!commit) { // dev mode
const vscodePath = path.resolve(path.join(context.extensionPath, '..', '..'));
const serverCommandPath = path.join(vscodePath, 'resources', 'server', 'bin-dev', serverCommand);
extHostProcess = cp.spawn(serverCommandPath, commandArgs, { env, cwd: vscodePath, detached: true });
extHostProcess = cp.spawn(serverCommandPath, commandArgs, { env, cwd: vscodePath });
} else {
const serverBin = path.join(remoteDataDir, 'bin');
progress.report({ message: 'Installing VSCode Server' });
const serverLocation = await downloadAndUnzipVSCodeServer(updateUrl, commit, quality, serverBin);
outputChannel.appendLine(`Using server build at ${serverLocation}`);
extHostProcess = cp.spawn(path.join(serverLocation, serverCommand), commandArgs, { env, cwd: serverLocation, detached: true });
extHostProcess = cp.spawn(path.join(serverLocation, serverCommand), commandArgs, { env, cwd: serverLocation });
}
extHostProcess.stdout.on('data', (data: Buffer) => processOutput(data.toString()));
extHostProcess.stderr.on('data', (data: Buffer) => processOutput(data.toString()));
@ -109,7 +110,7 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push({
dispose: () => {
if (extHostProcess) {
process.kill(-extHostProcess.pid);
terminateProcess(extHostProcess, context.extensionPath);
}
}
});

View file

@ -0,0 +1,37 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as cp from 'child_process';
import * as path from 'path';
export interface TerminateResponse {
success: boolean;
error?: any;
}
export function terminateProcess(p: cp.ChildProcess, extensionPath: string): TerminateResponse {
if (process.platform === 'win32') {
try {
const options: any = {
stdio: ['pipe', 'pipe', 'ignore']
};
cp.execFileSync('taskkill', ['/T', '/F', '/PID', p.pid.toString()], options);
} catch (err) {
return { success: false, error: err };
}
} else if (process.platform === 'darwin' || process.platform === 'linux') {
try {
const cmd = path.join(extensionPath, 'scripts', 'terminateProcess.sh');
const result = cp.spawnSync(cmd, [process.pid.toString()]);
if (result.error) {
return { success: false, error: result.error };
}
} catch (err) {
return { success: false, error: err };
}
} else {
p.kill('SIGKILL');
}
return { success: true };
}