diff --git a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts index a0396c822cd84..540c770e19f6b 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts @@ -1208,6 +1208,10 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { } override dispose(reason?: TerminalExitReason): void { + if (this._isDisposed) { + return; + } + this._isDisposed = true; this._logService.trace(`terminalInstance#dispose (instanceId: ${this.instanceId})`); dispose(this._linkManager); this._linkManager = undefined; @@ -1224,7 +1228,13 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { this._horizontalScrollbar.dispose(); this._horizontalScrollbar = undefined; } - this.xterm?.dispose(); + + try { + this.xterm?.dispose(); + } catch (err: unknown) { + // See https://github.com/microsoft/vscode/issues/153486 + this._logService.error('Exception occurred during xterm disposal', err); + } // HACK: Workaround for Firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=559561, // as 'blur' event in xterm.raw.textarea is not triggered on xterm.dispose() @@ -1249,10 +1259,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { // hasn't happened yet this._onProcessExit(undefined); - if (!this._isDisposed) { - this._isDisposed = true; - this._onDisposed.fire(this); - } + this._onDisposed.fire(this); + super.dispose(); }