Skip to content

Release terminal link cache and cancel pending link providers on terminal close#319184

Open
dmitrivMS wants to merge 1 commit into
mainfrom
dev/dmitriv/extHostTerminal-link-leak
Open

Release terminal link cache and cancel pending link providers on terminal close#319184
dmitrivMS wants to merge 1 commit into
mainfrom
dev/dmitriv/extHostTerminal-link-leak

Conversation

@dmitrivMS
Copy link
Copy Markdown
Contributor

Fixes a memory leak in BaseExtHostTerminalService where the per-terminal _terminalLinkCache and _terminalLinkCancellationSource maps were populated by $provideLinks but never released when a terminal was closed. Every terminal that ever had link providers queried leaked its cached ICachedLinkEntry map plus a CancellationTokenSource until the extension host exited.

Cleanup is now done in $acceptTerminalClosed (fires for all terminals, not just extension-owned ptys), and the in-flight cancellation source is dispose(true)-ed so any pending link-provider promises resolve instead of hanging.

Related to #310216 — that PR put the cleanup in _onProcessExit, which only runs for extension-pty terminals, so regular shell terminals would continue to leak.

Adds a unit test covering the cleanup behaviour.

…inal close

ExtHostTerminalService kept per-terminal entries in _terminalLinkCache and _terminalLinkCancellationSource forever:  populated them but nothing ever removed them when a terminal was closed. Each terminal that ever had links queried leaked its cached links plus a CancellationTokenSource until the extension host exited.

Clear both maps in  and dispose(true) the in-flight cancellation source so dangling provider promises resolve instead of hanging.
Copilot AI review requested due to automatic review settings May 31, 2026 01:55
@dmitrivMS dmitrivMS self-assigned this May 31, 2026
@dmitrivMS dmitrivMS added the perf label May 31, 2026
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

This PR fixes terminal link-provider state cleanup in the extension host so closed terminals no longer retain cached links or pending cancellation sources.

Changes:

  • Clears per-terminal link cache entries when $acceptTerminalClosed runs.
  • Cancels and removes any in-flight terminal link provider cancellation source on terminal close.
  • Adds a unit test covering cleanup and cancellation behavior.
Show a summary per file
File Description
src/vs/workbench/api/common/extHostTerminalService.ts Releases link cache and cancels pending link-provider work during terminal close handling.
src/vs/workbench/api/test/common/extHostTerminalService.test.ts Adds coverage for cleanup of cached link state and cancellation source disposal.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@dmitrivMS dmitrivMS requested a review from anthonykim1 May 31, 2026 01:59
@dmitrivMS dmitrivMS marked this pull request as ready for review May 31, 2026 01:59
@dmitrivMS dmitrivMS enabled auto-merge (squash) May 31, 2026 02:02
@dmitrivMS dmitrivMS disabled auto-merge May 31, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants