Skip to content

Commit

Permalink
watcher - do not dispose when shared process gone
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Oct 28, 2021
1 parent 061a665 commit 98b67fa
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/vs/platform/sharedProcess/electron-main/sharedProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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)}`);
}
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 98b67fa

Please sign in to comment.