Skip to content

fix: prevent DisposableStore leak per tree node in ExtHostTreeView (#346620) - #346727

Merged
Alex Ross (alexr00) merged 4 commits into
microsoft:mainfrom
wasim-builds:fix/issue-346620-tree-view-disposable-leak
Nov 12, 2026
Merged

Alex Ross (alexr00) merged 4 commits into
microsoft:mainfrom
wasim-builds:fix/issue-346620-tree-view-disposable-leak

Conversation

@wasim-builds

Copy link
Copy Markdown
Contributor

Resolves #346620

Summary

In src/vs/workbench/api/common/extHostTreeViews.ts, _createTreeNode() previously registered each tree node's new DisposableStore into the tree view's own DisposableStore via this._register(new DisposableStore()).

When a node was disposed (via _refreshNode(), _clearNodes(), or _createAndRegisterTreeNode()), existing.dispose() called disposableStore.dispose(), but never removed the DisposableStore instance from this._toDispose inside the tree view's store. As a result, the view's internal Set grew on every refresh indefinitely until V8's maximum Set limit (2^24 entries) was reached, throwing RangeError: Set maximum size exceeded on getChildren.

Changes

  1. In ExtHostTreeView._createTreeNode(): instantiate new DisposableStore() directly rather than registering it into the tree view's own store (this._store). Each TreeNode already tracks and disposes its disposableStore via its own dispose() method during node refreshes, replacements, node clearing (_clearNodes()), and overall view disposal (_clearAll()).
  2. In ExtHostTreeView.dispose(): invoke this._clearAll() before super.dispose() to ensure all tree node resources and command caches are released cleanly prior to disposing view event listeners.
  3. Added a regression test in src/vs/workbench/api/test/browser/extHostTreeViews.test.ts verifying that repeated node fetches and refreshes do not grow the tree view's DisposableStore.
…icrosoft#346620)

ExtHostTreeView registered each tree node's new DisposableStore into the
tree view's own DisposableStore via this._register(). Disposing a node
disposed that inner store, but never removed it from the view's _toDispose
Set, leading to continuous growth on every refresh until V8's maximum Set
size (2^24) was exceeded with RangeError: Set maximum size exceeded.

Each TreeNode already owns its disposableStore and disposes it via
node.dispose() on refresh, clear, and view disposal. Do not register
per-node disposableStores into the view's lifetime store.
Copilot AI balanced review requested due to automatic review settings November 7, 2026 05:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues

Review effort: Lite

Copilot stopped reviewing on behalf of Alex Ross (alexr00) due to an error November 11, 2026 16:15
Alex Ross (alexr00) and others added 2 commits November 11, 2026 18:46
…ilure

Dispose the newly allocated DisposableStore in _createTreeNode if an error
is thrown before TreeNode ownership is handed off, and update regression test
to compare store size against post-first-fetch count across repeated refreshes.

Addresses Copilot review feedback on microsoft#346727.
@wasim-builds

Copy link
Copy Markdown
Contributor Author

Addressed review feedback in commit b321968909e:

  1. Guard _createTreeNode on failure: Wrapped the handle, tree item mapping, and node construction in a try/catch block that invokes disposableStore.dispose() on error before re-throwing, ensuring that any exception thrown before TreeNode ownership hand-off cleans up the allocated store.
  2. Robust regression test comparison: Updated extHostTreeViews.test.ts to assert that repeated refreshes do not grow the view store size relative to the post-first-fetch count (afterRefreshesCount === afterFirstFetchCount).

All 37 unit tests in extHostTreeViews.test.ts pass and 0 eslint errors.

@alexr00 Alex Ross (alexr00) added this to the 1.147.0 milestone Nov 12, 2026
@alexr00
Alex Ross (alexr00) enabled auto-merge (squash) November 12, 2026 10:17
@alexr00
Alex Ross (alexr00) merged commit a60182f into microsoft:main Nov 12, 2026
52 of 53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants