prevent an extension from process.exit() (fixes #411)

This commit is contained in:
Benjamin Pasero
2015-11-22 10:18:57 +01:00
parent bff376d138
commit 2b6ba9e3cb
2 changed files with 10 additions and 4 deletions

View File

@@ -55,6 +55,12 @@ export interface IInitData {
};
}
const nativeExit = process.exit;
process.exit = () => { console.warn('An extension called process.exit() and this was prevented'); };
export function exit(code?: number) {
nativeExit(code);
}
export function createServices(remoteCom: IPluginsIPC, initData: IInitData, sharedProcessClient: Client): IInstantiationService {
// the init data is not demarshalled
initData = marshalling.deserialize(initData);
@@ -249,7 +255,7 @@ export class PluginHostMain {
private gracefulExit(): void {
// to give the PH process a chance to flush any outstanding console
// messages to the main process, we delay the process.exit() by some time
setTimeout(() => process.exit(), 500);
// messages to the main process, we delay the exit() by some time
setTimeout(() => exit(), 500);
}
}

View File

@@ -7,7 +7,7 @@
import {onUnexpectedError} from 'vs/base/common/errors';
import { TPromise } from 'vs/base/common/winjs.base';
import { PluginHostMain, createServices, IInitData } from 'vs/workbench/node/pluginHostMain';
import { PluginHostMain, createServices, IInitData, exit } from 'vs/workbench/node/pluginHostMain';
import { Client, connect } from 'vs/base/node/service.net';
import { create as createIPC, IPluginsIPC } from 'vs/platform/plugins/common/ipcRemoteCom';
@@ -50,7 +50,7 @@ function connectToRenderer(): TPromise<IRendererConnection> {
try {
process.kill(msg.parentPid, 0); // throws an exception if the main process doesn't exist anymore.
} catch (e) {
process.exit();
exit();
}
}, 5000);