Skip to content

Commit

Permalink
Revert "Reconnect same host plugin process and client"
Browse files Browse the repository at this point in the history
This reverts commit 797db75.

Signed-off-by: Anton Kosiakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Sep 19, 2019
1 parent e8d8233 commit ce9e771
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 120 deletions.
4 changes: 0 additions & 4 deletions packages/plugin-ext/src/common/plugin-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,6 @@ export function buildFrontendModuleName(plugin: PluginPackage | PluginModel): st

export const HostedPluginClient = Symbol('HostedPluginClient');
export interface HostedPluginClient {
setClientId(clientId: number): Promise<void>;

getClientId(): Promise<number>;

postMessage(message: string): Promise<void>;

log(logPart: LogPart): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ export class HostedPluginWatcher {
getHostedPluginClient(): HostedPluginClient {
const messageEmitter = this.onPostMessage;
const logEmitter = this.onLogMessage;
let clientId = 0;
return {
getClientId: () => Promise.resolve(clientId),
setClientId: (id: number) => {
clientId = id;
return Promise.resolve();
},
postMessage(message: string): Promise<void> {
messageEmitter.fire(JSON.parse(message));
return Promise.resolve();
Expand Down
32 changes: 1 addition & 31 deletions packages/plugin-ext/src/hosted/node/hosted-plugin-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { HostedPluginClient, ServerPluginRunner, PluginMetadata, PluginHostEnvir
import { RPCProtocolImpl } from '../../common/rpc-protocol';
import { MAIN_RPC_CONTEXT } from '../../common/plugin-api-rpc';
import { HostedPluginCliContribution } from './hosted-plugin-cli-contribution';
import { HostedPluginProcessesCache } from './hosted-plugin-processes-cache';
import * as psTree from 'ps-tree';

export interface IPCConnectionOptions {
Expand All @@ -43,9 +42,6 @@ export class HostedPluginProcess implements ServerPluginRunner {
@inject(HostedPluginCliContribution)
protected readonly cli: HostedPluginCliContribution;

@inject(HostedPluginProcessesCache)
protected readonly pluginProcessCache: HostedPluginProcessesCache;

@inject(ContributionProvider)
@named(PluginHostEnvironmentVariable)
protected readonly pluginHostEnvironmentVariables: ContributionProvider<PluginHostEnvironmentVariable>;
Expand All @@ -54,29 +50,17 @@ export class HostedPluginProcess implements ServerPluginRunner {
protected readonly messageService: MessageService;

private childProcess: cp.ChildProcess | undefined;

private client: HostedPluginClient;

private terminatingPluginServer = false;

private async getClientId(): Promise<number> {
return await this.pluginProcessCache.getLazyClientId(this.client);
}

public setClient(client: HostedPluginClient): void {
if (this.client) {
if (this.childProcess) {
this.runPluginServer();
}
}
this.client = client;
this.getClientId().then(clientId => {
const childProcess = this.pluginProcessCache.retrieveClientChildProcess(clientId);
if (!this.childProcess && childProcess) {
this.childProcess = childProcess;
this.linkClientWithChildProcess(this.childProcess);
}
});
}

public clientClosed(): void {
Expand All @@ -99,12 +83,6 @@ export class HostedPluginProcess implements ServerPluginRunner {
}
}

public markPluginServerTerminated(): void {
if (this.childProcess) {
this.pluginProcessCache.scheduleChildProcessTermination(this, this.childProcess);
}
}

public terminatePluginServer(): void {
if (this.childProcess === undefined) {
return;
Expand Down Expand Up @@ -153,19 +131,11 @@ export class HostedPluginProcess implements ServerPluginRunner {
logger: this.logger,
args: []
});
this.linkClientWithChildProcess(this.childProcess);

}

private linkClientWithChildProcess(childProcess: cp.ChildProcess): void {
childProcess.on('message', message => {
this.childProcess.on('message', message => {
if (this.client) {
this.client.postMessage(message);
}
});
this.getClientId().then(clientId => {
this.pluginProcessCache.linkLiveClientAndProcess(clientId, childProcess);
});
}

readonly HOSTED_PLUGIN_ENV_REGEXP_EXCLUSION = new RegExp('HOSTED_PLUGIN*');
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion packages/plugin-ext/src/hosted/node/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class HostedPluginSupport {
}

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

public runPluginServer(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { HostedPluginProcess } from './hosted-plugin-process';
import { ExtPluginApiProvider } from '../../common/plugin-ext-api-contribution';
import { HostedPluginCliContribution } from './hosted-plugin-cli-contribution';
import { HostedPluginDeployerHandler } from './hosted-plugin-deployer-handler';
import { HostedPluginProcessesCache } from './hosted-plugin-processes-cache';

const commonHostedConnectionModule = ConnectionContainerModule.create(({ bind, bindBackendService }) => {
bind(HostedPluginProcess).toSelf().inSingletonScope();
Expand All @@ -49,7 +48,6 @@ const commonHostedConnectionModule = ConnectionContainerModule.create(({ bind, b
});

export function bindCommonHostedBackend(bind: interfaces.Bind): void {
bind(HostedPluginProcessesCache).toSelf().inSingletonScope();
bind(HostedPluginCliContribution).toSelf().inSingletonScope();
bind(CliContribution).toService(HostedPluginCliContribution);

Expand Down
9 changes: 6 additions & 3 deletions packages/plugin-ext/src/main/browser/connection-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { DisposableCollection } from '@theia/core/lib/common/disposable';
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
import { MAIN_RPC_CONTEXT, ConnectionMain, ConnectionExt } from '../../common/plugin-api-rpc';
import { RPCProtocol } from '../../common/rpc-protocol';
import { PluginConnection } from '../../common/connection';
Expand Down Expand Up @@ -96,9 +96,12 @@ export class ConnectionMainImpl implements ConnectionMain {
writer,
() => {
this.connections.delete(id);
this.proxy.$deleteConnection(id);
if (!toClose.disposed) {
this.proxy.$deleteConnection(id);
}
});
this.toDispose.push(connection);
const toClose = new DisposableCollection(Disposable.create(() => reader.fireClose()));
this.toDispose.push(toClose);
return connection;
}
}

0 comments on commit ce9e771

Please sign in to comment.