Repository navigation
fix: memory leak in terminal disposal subscriptions - #340037
Merged
Dmitriy Vasyura (dmitrivMS) merged 7 commits intoOct 11, 2026
Merged
Dmitriy Vasyura (dmitrivMS) merged 7 commits into
Dmitriy Vasyura (dmitrivMS) merged 7 commits into
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused lifecycle change removes the leak while preserving terminal cleanup behavior with relevant regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes per-terminal disposal subscription growth in the terminal API service.
Changes:
- Reuses the global terminal-disposal listener to remove extension-host mappings.
- Adds lifecycle and memory regression tests.
| File | Description |
|---|---|
mainThreadTerminalService.ts |
Centralizes API terminal cleanup. |
mainThreadTerminalService.test.ts |
Tests disposal, collection, and live-terminal preservation. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Collaborator
|
Simon Siefke (@SimonSiefke) Thank you! |
Dmitriy Vasyura (dmitrivMS)
enabled auto-merge (squash)
October 6, 2026 19:18
Dmitriy Vasyura (dmitrivMS)
approved these changes
Oct 6, 2026
Aaron Munger (amunger)
previously approved these changes
Oct 6, 2026
roblourens
previously approved these changes
Oct 6, 2026
Sandeep Somavarapu (sandy081)
previously approved these changes
Oct 6, 2026
Dmitriy Vasyura (dmitrivMS)
requested changes
Oct 7, 2026
Collaborator
There was a problem hiding this comment.
Memory leaks:
1) MainThreadTerminalService
"after each" hook for "releases the launch request after an API terminal closes":
@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/test/common/utils.js:45:24
@http://localhost:49608/12011c733dde34e0200096e9061d4a61/test/unit/browser/renderer.html:56:27
2026-10-06T23:30:59.652Z pw:browser [pid=28574] <gracefully close start>
2026-10-06T23:30:59.852Z pw:browser [pid=28574] <process did exit: exitCode=0, signal=null>
2026-10-06T23:30:59.852Z pw:browser [pid=28574] starting temporary directories cleanup
The followings tests are failing:
2026-10-06T23:30:59.854Z pw:browser [pid=28574] finished temporary directories cleanup
- MainThreadTerminalService "after each" hook for "releases the launch request after an API terminal closes" (reason: There are 2 undisposed disposables!
2026-10-06T23:30:59.854Z pw:browser [pid=28574] <gracefully close end>
==================== Leaking disposable 1/2: FunctionDisposable ====================
(shared with 1/2 leaks) at trackDisposable@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/lifecycle.js:51:40
(shared with 1/2 leaks) at trackDisposable@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/lifecycle.js:192:37
(shared with 1/2 leaks) at FunctionDisposable@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/lifecycle.js:256:20
(shared with 1/2 leaks) at toDisposable@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/lifecycle.js:271:32
(shared with 1/2 leaks) at @http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/event.js:758:34
(shared with 1/2 leaks) at @http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/async.js:370:53
(shared with 1/2 leaks) at Promise@[native code]
(shared with 1/2 leaks) at timeout@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/async.js:365:21
(shared with 1/2 leaks) at createCancelablePromise@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/async.js:14:28
- stacktraces of 1 other leaks continue with createCancelablePromise@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/async.js:16:30
(shared with 2/2 leaks) at TerminalService@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/workbench/contrib/terminal/browser/terminalService.js:138:12
(shared with 2/2 leaks) at construct@[native code]
(shared with 2/2 leaks) at createInstance@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/platform/instantiation/common/instantiationService.js:93:36
(shared with 2/2 leaks) at @http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/workbench/api/test/browser/mainThreadTerminalService.test.js:56:62
(shared with 2/2 leaks) at callFn@http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:13313:27
(shared with 2/2 leaks) at @http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:13301:13
(shared with 2/2 leaks) at next@http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:14689:15
(shared with 2/2 leaks) at cbHookRun@http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:14730:13
(shared with 2/2 leaks) at done@http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:13257:9
(shared with 2/2 leaks) at callFn@http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:13336:13
(shared with 2/2 leaks) at @http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:13301:13
(shared with 2/2 leaks) at next@http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:14689:15
(shared with 2/2 leaks) at @http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:14750:11
(shared with 2/2 leaks) at @http://localhost:49608/12011c733dde34e0200096e9061d4a61/test/unit/browser/renderer.html:56:27
============================================================
==================== Leaking disposable 2/2: FunctionDisposable ====================
(shared with 1/2 leaks) at trackDisposable@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/lifecycle.js:51:40
(shared with 1/2 leaks) at trackDisposable@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/lifecycle.js:192:37
(shared with 1/2 leaks) at FunctionDisposable@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/lifecycle.js:256:20
(shared with 1/2 leaks) at toDisposable@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/lifecycle.js:271:32
(shared with 1/2 leaks) at @http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/event.js:758:34
(shared with 1/2 leaks) at @http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/async.js:17:62
(shared with 1/2 leaks) at Promise@[native code]
(shared with 1/2 leaks) at createCancelablePromise@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/async.js:16:30
- stacktraces of 1 other leaks continue with createCancelablePromise@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/base/common/async.js:14:28
(shared with 2/2 leaks) at TerminalService@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/workbench/contrib/terminal/browser/terminalService.js:138:12
(shared with 2/2 leaks) at construct@[native code]
(shared with 2/2 leaks) at createInstance@http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/platform/instantiation/common/instantiationService.js:93:36
(shared with 2/2 leaks) at @http://localhost:49608/12011c733dde34e0200096e9061d4a61/out/vs/workbench/api/test/browser/mainThreadTerminalService.test.js:56:62
(shared with 2/2 leaks) at callFn@http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:13313:27
(shared with 2/2 leaks) at @http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:13301:13
(shared with 2/2 leaks) at next@http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:14689:15
(shared with 2/2 leaks) at cbHookRun@http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:14730:13
(shared with 2/2 leaks) at done@http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:13257:9
(shared with 2/2 leaks) at callFn@http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:13336:13
(shared with 2/2 leaks) at @http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:13301:13
(shared with 2/2 leaks) at next@http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:14689:15
(shared with 2/2 leaks) at @http://localhost:49608/12011c733dde34e0200096e9061d4a61/node_modules/mocha/mocha.js:14750:11
(shared with 2/2 leaks) at @http://localhost:49608/12011c733dde34e0200096e9061d4a61/test/unit/browser/renderer.html:56:27
============================================================
auto-merge was automatically disabled
October 7, 2026 15:31
Head branch was pushed to by a user without write access
Simon Siefke (SimonSiefke)
dismissed stale reviews from Sandeep Somavarapu (sandy081), roblourens, and Aaron Munger (amunger)
via
October 7, 2026 15:31
9ab313a
Contributor
Author
|
Fixed another race condition in terminal disposal logic, should be good now. |
Dmitriy Vasyura (dmitrivMS)
requested changes
Oct 9, 2026
Dmitriy Vasyura (dmitrivMS)
left a comment
Collaborator
There was a problem hiding this comment.
Please see comment
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Anthony Kim (@anthonykim1)Matched files:
|
Dmitriy Vasyura (dmitrivMS)
approved these changes
Oct 11, 2026
Dmitriy Vasyura (dmitrivMS)
enabled auto-merge (squash)
October 11, 2026 07:28
Martin Aeschlimann (aeschli)
approved these changes
Oct 11, 2026
Vijay Upadya (vijayupadya)
approved these changes
Oct 11, 2026
Dmitriy Vasyura (dmitrivMS)
merged commit Oct 11, 2026
6133b42
into
microsoft:main
55 of 56 checks passed
Simon Siefke (SimonSiefke)
deleted the
fix/memory-leak-terminal-disposalSubscriptions
branch
October 13, 2026 09:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Details
Each API terminal adds an onDisposed subscription to MainThreadTerminalService’s lifetime store. Closing the terminal removes its API mapping but leaves the subscription and launch configuration in that store.
Change
Keep the direct terminal-disposal listener and remove its subscription from the service store when the terminal closes. This preserves API mapping cleanup when a terminal is detached from its group before disposal. Also clear mappings for terminals closed during creation, and await queued TerminalService initialization in test setup so skipped GC tests leave no pending disposables.
Before
Creating and closing 37 API terminals with a missing shell adds 37 disposal callbacks. The service’s lifetime store grows from 21 to 58 entries.
After
The launch-request regression passes with exposed GC and fails when listener self-cleanup is reverted. Focused tests on Linux pass in WebKit (5 passed, 1 expected GC skip) and Chromium with exposed GC (6 passed), including detached-terminal and early-closure coverage. The selected module, including imported xterm tests, passes all 33 tests in Chromium. Focused ESLint passes.
Test Video
Original reproduction recording: seven failed terminal launches and closures. The missing-shell notification is the expected test trigger; a live Bash terminal remains.
test.mp4
AI disclosure: Model: GPT 6 Astra. Worktime: 48 min