From 98b67faef42f107c44fc1401d5fac418c19c7e85 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 28 Oct 2021 09:02:37 +0200 Subject: [PATCH] watcher - do not dispose when shared process gone --- .../electron-main/sharedProcess.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/vs/platform/sharedProcess/electron-main/sharedProcess.ts b/src/vs/platform/sharedProcess/electron-main/sharedProcess.ts index c196c2d918b..36cd750dc0c 100644 --- a/src/vs/platform/sharedProcess/electron-main/sharedProcess.ts +++ b/src/vs/platform/sharedProcess/electron-main/sharedProcess.ts @@ -92,6 +92,10 @@ export class SharedProcess extends Disposable implements ISharedProcess { const disposables = new DisposableStore(); const disposeWorker = (reason: string) => { + if (!this.isAlive()) { + return; // the shared process is already gone, no need to dispose anything + } + this.logService.trace(`SharedProcess: disposing worker (reason: '${reason}')`, configuration); // Only once! @@ -152,14 +156,13 @@ export class SharedProcess extends Disposable implements ISharedProcess { } private send(channel: string, ...args: any[]): void { - const window = this.window; - if (!window || window.isDestroyed() || window.webContents.isDestroyed()) { + if (!this.isAlive()) { this.logService.warn(`Sending IPC message to channel '${channel}' for shared process window that is destroyed`); return; } try { - window.webContents.send(channel, ...args); + this.window?.webContents.send(channel, ...args); } catch (error) { this.logService.warn(`Error sending IPC message to channel '${channel}' of shared process: ${toErrorMessage(error)}`); } @@ -305,4 +308,13 @@ export class SharedProcess extends Disposable implements ISharedProcess { isVisible(): boolean { return this.window?.isVisible() ?? false; } + + private isAlive(): boolean { + const window = this.window; + if (!window) { + return false; + } + + return !window.isDestroyed() && !window.webContents.isDestroyed(); + } }