diff --git a/src/vs/platform/terminal/node/ptyService.ts b/src/vs/platform/terminal/node/ptyService.ts index ec71ad484b4..89a37150b5a 100644 --- a/src/vs/platform/terminal/node/ptyService.ts +++ b/src/vs/platform/terminal/node/ptyService.ts @@ -519,7 +519,8 @@ export class PtyService extends Disposable implements IPtyService { performance.mark('code/willGetTerminalLayoutInfo'); const layout = this._workspaceLayoutInfos.get(args.workspaceId); if (layout) { - const expandedTabs = await Promise.all(layout.tabs.map(async tab => this._expandTerminalTab(args.workspaceId, tab))); + const doneSet: Set = new Set(); + const expandedTabs = await Promise.all(layout.tabs.map(async tab => this._expandTerminalTab(args.workspaceId, tab, doneSet))); const tabs = expandedTabs.filter(t => t.terminals.length > 0); performance.mark('code/didGetTerminalLayoutInfo'); return { tabs }; @@ -528,8 +529,8 @@ export class PtyService extends Disposable implements IPtyService { return undefined; } - private async _expandTerminalTab(workspaceId: string, tab: ITerminalTabLayoutInfoById): Promise { - const expandedTerminals = (await Promise.all(tab.terminals.map(t => this._expandTerminalInstance(workspaceId, t)))); + private async _expandTerminalTab(workspaceId: string, tab: ITerminalTabLayoutInfoById, doneSet: Set): Promise { + const expandedTerminals = (await Promise.all(tab.terminals.map(t => this._expandTerminalInstance(workspaceId, t, doneSet)))); const filtered = expandedTerminals.filter(term => term.terminal !== null) as IRawTerminalInstanceLayoutInfo[]; return { isActive: tab.isActive, @@ -538,13 +539,17 @@ export class PtyService extends Disposable implements IPtyService { }; } - private async _expandTerminalInstance(workspaceId: string, t: ITerminalInstanceLayoutInfoById): Promise> { + private async _expandTerminalInstance(workspaceId: string, t: ITerminalInstanceLayoutInfoById, doneSet: Set): Promise> { try { const oldId = this._getRevivingProcessId(workspaceId, t.terminal); const revivedPtyId = this._revivedPtyIdMap.get(oldId)?.newId; this._logService.info(`Expanding terminal instance, old id ${oldId} -> new id ${revivedPtyId}`); this._revivedPtyIdMap.delete(oldId); const persistentProcessId = revivedPtyId ?? t.terminal; + if (doneSet.has(persistentProcessId)) { + throw new Error(`Terminal ${persistentProcessId} has already been expanded`); + } + doneSet.add(persistentProcessId); const persistentProcess = this._throwIfNoPty(persistentProcessId); const processDetails = persistentProcess && await this._buildProcessDetails(t.terminal, persistentProcess, revivedPtyId !== undefined); return {