Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8428-stop-hosted-instance #8674

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions packages/plugin-dev/src/node/hosted-instance-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ import { FileUri } from '@theia/core/lib/node/file-uri';
import { LogType } from '@theia/plugin-ext/lib/common/types';
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/node/hosted-plugin';
import { MetadataScanner } from '@theia/plugin-ext/lib/hosted/node/metadata-scanner';

const processTree = require('ps-tree');
import { HostedPluginProcess } from '@theia/plugin-ext/lib/hosted/node/hosted-plugin-process';

export const HostedInstanceManager = Symbol('HostedInstanceManager');

Expand Down Expand Up @@ -109,6 +108,9 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan
@inject(MetadataScanner)
protected readonly metadata: MetadataScanner;

@inject(HostedPluginProcess)
protected readonly hostedPluginProcess: HostedPluginProcess;

isRunning(): boolean {
return this.isPluginRunning;
}
Expand Down Expand Up @@ -156,13 +158,9 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan

terminate(): void {
if (this.isPluginRunning) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
processTree(this.hostedInstanceProcess.pid, (err: Error, children: Array<any>) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const args = ['-SIGTERM', this.hostedInstanceProcess.pid.toString()].concat(children.map((p: any) => p.PID));
cp.spawn('kill', args);
});
this.hostedPluginProcess.killProcessTree(this.hostedInstanceProcess.pid);
this.hostedPluginSupport.sendLog({ data: 'Hosted instance has been terminated', type: LogType.Info });
this.isPluginRunning = false;
} else {
throw new Error('Hosted plugin instance is not running.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class HostedPluginProcess implements ServerPluginRunner {
this.killProcessTree(cp.pid);
}

private killProcessTree(parentPid: number): void {
killProcessTree(parentPid: number): void {
psTree(parentPid, (_, childProcesses) => {
childProcesses.forEach(childProcess =>
this.killProcess(parseInt(childProcess.PID))
Expand Down
18 changes: 8 additions & 10 deletions packages/plugin-ext/src/hosted/node/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface IPCConnectionOptions {

@injectable()
export class HostedPluginSupport {
private isPluginProcessRunning = false;
private client: HostedPluginClient;

@inject(ILogger)
Expand All @@ -37,8 +38,6 @@ export class HostedPluginSupport {
@inject(HostedPluginProcess)
protected readonly hostedPluginProcess: HostedPluginProcess;

private isPluginProcessRunning = false;

/**
* Optional runners to delegate some work
*/
Expand Down Expand Up @@ -87,11 +86,7 @@ export class HostedPluginSupport {
}
}

private terminatePluginServer(): void {
this.hostedPluginProcess.terminatePluginServer();
}

public runPluginServer(): void {
runPluginServer(): void {
if (!this.isPluginProcessRunning) {
this.hostedPluginProcess.runPluginServer();
this.isPluginProcessRunning = true;
Expand All @@ -101,19 +96,22 @@ export class HostedPluginSupport {
/**
* Provides additional plugin ids.
*/
public async getExtraDeployedPluginIds(): Promise<string[]> {
async getExtraDeployedPluginIds(): Promise<string[]> {
return [].concat.apply([], await Promise.all(this.pluginRunners.map(runner => runner.getExtraDeployedPluginIds())));
}

/**
* Provides additional deployed plugins.
*/
public async getExtraDeployedPlugins(): Promise<DeployedPlugin[]> {
async getExtraDeployedPlugins(): Promise<DeployedPlugin[]> {
return [].concat.apply([], await Promise.all(this.pluginRunners.map(runner => runner.getExtraDeployedPlugins())));
}

public sendLog(logPart: LogPart): void {
sendLog(logPart: LogPart): void {
this.client.log(logPart);
}

private terminatePluginServer(): void {
this.hostedPluginProcess.terminatePluginServer();
}
}