diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index bc9a5dba8c8..7792c22fd6e 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -60,7 +60,7 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle import { IIssueMainService, IssueMainService } from 'vs/platform/issue/electron-main/issueMainService'; import { IKeyboardLayoutMainService, KeyboardLayoutMainService } from 'vs/platform/keyboardLayout/electron-main/keyboardLayoutMainService'; import { ILaunchMainService, LaunchMainService } from 'vs/platform/launch/electron-main/launchMainService'; -import { ILifecycleMainService, LifecycleMainPhase } from 'vs/platform/lifecycle/electron-main/lifecycleMainService'; +import { ILifecycleMainService, LifecycleMainPhase, ShutdownReason } from 'vs/platform/lifecycle/electron-main/lifecycleMainService'; import { ILoggerService, ILogService } from 'vs/platform/log/common/log'; import { LoggerChannel, LogLevelChannel } from 'vs/platform/log/common/logIpc'; import { IMenubarMainService, MenubarMainService } from 'vs/platform/menubar/electron-main/menubarMainService'; @@ -471,6 +471,16 @@ export class CodeApplication extends Disposable { // Main process server (electron IPC based) const mainProcessElectronServer = new ElectronIPCServer(); + this.lifecycleMainService.onWillShutdown(e => { + if (e.reason === ShutdownReason.KILL) { + // When we go down abnormally, make sure to free up + // any IPC we accept from other windows to reduce + // the chance of doing work after we go down. Kill + // is special in that it does not orderly shutdown + // windows. + mainProcessElectronServer.dispose(); + } + }); // Resolve unique machine ID this.logService.trace('Resolving machine identifier...'); diff --git a/src/vs/platform/lifecycle/electron-main/lifecycleMainService.ts b/src/vs/platform/lifecycle/electron-main/lifecycleMainService.ts index 6b9dd062653..ac3b7bfb3b2 100644 --- a/src/vs/platform/lifecycle/electron-main/lifecycleMainService.ts +++ b/src/vs/platform/lifecycle/electron-main/lifecycleMainService.ts @@ -599,8 +599,8 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe }; app.once('quit', quitListener); - // app.relaunch() does not quit automatically, so we quit first, - // check for vetoes and then relaunch from the app.on('quit') event + // `app.relaunch()` does not quit automatically, so we quit first, + // check for vetoes and then relaunch from the `app.on('quit')` event const veto = await this.quit(true /* will restart */); if (veto) { app.removeListener('quit', quitListener); @@ -623,10 +623,13 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe await Promise.race([ - // still do not block more than 1s + // Still do not block more than 1s timeout(1000), - // destroy any opened window + // Destroy any opened window: we do not unload windows here because + // there is a chance that the unload is veto'd or long running due + // to a participant within the window. this is not wanted when we + // are asked to kill the application. (async () => { for (const window of BrowserWindow.getAllWindows()) { if (window && !window.isDestroyed()) { diff --git a/src/vs/platform/storage/electron-main/storageMainService.ts b/src/vs/platform/storage/electron-main/storageMainService.ts index 53491f6f089..36658666615 100644 --- a/src/vs/platform/storage/electron-main/storageMainService.ts +++ b/src/vs/platform/storage/electron-main/storageMainService.ts @@ -44,8 +44,6 @@ export class StorageMainService extends Disposable implements IStorageMainServic declare readonly _serviceBrand: undefined; - private willShutdown: boolean = false; - constructor( @ILogService private readonly logService: ILogService, @IEnvironmentService private readonly environmentService: IEnvironmentService, @@ -82,8 +80,6 @@ export class StorageMainService extends Disposable implements IStorageMainServic this._register(this.lifecycleMainService.onWillShutdown(e => { this.logService.trace('storageMainService#onWillShutdown()'); - this.willShutdown = true; - // Global Storage e.join(this.globalStorage.close()); @@ -118,10 +114,6 @@ export class StorageMainService extends Disposable implements IStorageMainServic private readonly mapWorkspaceToStorage = new Map(); workspaceStorage(workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier): IStorageMain { - if (this.willShutdown) { - throw new Error('Refusing to create workspace storage for application will shutdown.'); - } - let workspaceStorage = this.mapWorkspaceToStorage.get(workspace.id); if (!workspaceStorage) { this.logService.trace(`StorageMainService: creating workspace storage (${workspace.id})`);