Skip to content

fix: release terminal startup promises on dispose#319855

Open
vivekjm wants to merge 2 commits into
microsoft:mainfrom
vivekjm:fix-terminal-startup-promise-leak
Open

fix: release terminal startup promises on dispose#319855
vivekjm wants to merge 2 commits into
microsoft:mainfrom
vivekjm:fix-terminal-startup-promise-leak

Conversation

@vivekjm
Copy link
Copy Markdown
Contributor

@vivekjm vivekjm commented Jun 4, 2026

Fixes #276610

Details

TerminalInstance kept per-instance startup promises and barriers after disposal. Creating and disposing terminals repeatedly could leave the frontend startup promise/barrier objects retained after the instance was already gone.

This change opens any pending startup barriers during dispose, clears the xterm-ready promise and barrier references, and keeps the public readiness helpers safe after disposal by returning already-resolved fallback promises.

Evidence

Before: the issue repro reported retained promises growing with terminal create/delete cycles, with stacks pointing at terminalInstance.ts startup promise/barrier creation.

After: the added regression test disposes a terminal instance, verifies _xtermReadyPromise, _containerReadyBarrier, and _attachBarrier are cleared, and verifies post-dispose xtermReadyPromise and focusWhenReady() remain safe.

Validation

  • npm ci in /tmp/vscode-pr-check with Node 24.15.0
  • npm run compile-check-ts-native -- --pretty false
  • npm run gulp compile-client
  • npm run test-browser-no-install -- --browser chromium --run src/vs/workbench/contrib/terminal/test/browser/terminalInstance.test.ts --grep "release startup promises"
  • npm run test-browser-no-install -- --browser chromium --run src/vs/workbench/contrib/terminal/test/browser/terminalInstance.test.ts (94 passing, 2 pending)
  • node build/eslint.ts src/vs/workbench/contrib/terminal/browser/terminalInstance.ts src/vs/workbench/contrib/terminal/test/browser/terminalInstance.test.ts
  • git diff --check origin/main...HEAD

Copilot AI review requested due to automatic review settings June 4, 2026 06:22
@vs-code-engineering
Copy link
Copy Markdown
Contributor

vs-code-engineering Bot commented Jun 4, 2026

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@anthonykim1

Matched files:

  • src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
  • src/vs/workbench/contrib/terminal/test/browser/terminalInstance.test.ts

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds disposal-time cleanup for TerminalInstance startup synchronization so callers don’t hang on pending barriers/promises after an instance is disposed.

Changes:

  • Make internal startup promise/barriers nullable and provide safe fallbacks (xtermReadyPromise, barrier waits).
  • Ensure disposal opens barriers and clears references to release waiters.
  • Add a regression test verifying promises/barriers are released and focusWhenReady() completes after dispose.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/vs/workbench/contrib/terminal/test/browser/terminalInstance.test.ts Adds a regression test that exercises dispose behavior around startup promises/barriers.
src/vs/workbench/contrib/terminal/browser/terminalInstance.ts Clears startup sync primitives on dispose and makes waits resilient when disposed.

Comment thread src/vs/workbench/contrib/terminal/browser/terminalInstance.ts Outdated
Comment thread src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Comment thread src/vs/workbench/contrib/terminal/test/browser/terminalInstance.test.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Promise memory leak when creating terminal (frontend)

4 participants