Skip to content

fix: memory leak in extHostTimeline - #334098

Merged
Dmitriy Vasyura (dmitrivMS) merged 8 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-extHostTimeline
Oct 5, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 8 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-extHostTimeline

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

When a timeline provider caches results, extHostTimeline stores each item under the provider ID and resource URI. But disposing the provider looks for that ID inside the URI maps, so the provider's cache entry is not removed.

Change

Delete the provider's top-level cache entry when its wrapped provider is disposed.

Before

When registering, requesting, and disposing 37 timeline providers, timeline items and their command callbacks grow once per cycle:

extHostTimeline-before

After

No more timeline provider cache leak is detected.

Test Video

test-video.webm

Copilot AI balanced review requested due to automatic review settings September 2, 2026 19:46

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.

🟡 Changes recommended

An in-flight request can repopulate the cache after disposal; generation/disposal handling and race coverage are needed.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes timeline provider cache cleanup after disposal.

Changes:

  • Deletes provider-level cached timeline entries on disposal.
  • Adds regression coverage for cache cleanup and re-registration.
File summaries
File Description
src/vs/workbench/api/test/browser/extHostTimeline.test.ts Tests cache cleanup after disposal.
src/vs/workbench/api/common/extHostTimeline.ts Corrects provider cache deletion.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@dmitrivMS

Copy link
Copy Markdown
Collaborator

P2 / Medium: suppressing a disposed provider's late result can leave a healthy provider's pagination stuck

Static-review finding against 3b8c37013aa13d2a11183fcca87ed86f56b58c62; the reproduction below has not been executed in Code OSS. This requires a narrow disposal/completion race and is recoverable with a refresh; no data loss or crash is claimed.

The new disposed-result guard correctly prevents stale items and commands from being cached. However, its new undefined result exposes a loading-state problem in the Timeline pane:

  1. Removing provider A refreshes the tree without removing A's pending request. If surviving provider B has pageable items, that refresh creates a loading load-more row and clears _pendingRefresh.
  2. When A's promise resolves, the new guard returns undefined. Request completion removes A from the pending map, but the empty-response branch skips refreshing when _pendingRefresh is false.
  3. The rendered row therefore remains marked loading, and the load-more handler rejects it, preventing B from fetching its next page even though no request remains.

Proposed reproduction

Use a development extension with the timeline proposal enabled and two synthetic timeline providers:

  1. Register B so its first request completes immediately with an item and paging: { cursor: 'next' }.
  2. Open a file's Timeline, with other sources excluded to avoid unrelated updates. Keep the pane visible and focused; wait for B's first page to finish.
  3. Register A with a provideTimeline implementation returning a controllable, unresolved promise. Wait until A's request starts, then dispose A's registration without replacing it.
  4. Let any previously scheduled 500-ms focus/debounce refresh finish. Keep focus unchanged and allow no further provider changes.
  5. Resolve A's original promise with a nonempty timeline result. Once that request completes, attempt to load B's next page, including via scrolling.

Expected: A's stale result is discarded, but B's pagination becomes available again.
Predicted from the code: the row remains Loading... and pagination is ignored until an explicit refresh, a focus transition that schedules a refresh, or another qualifying update.

The pane's handling of genuinely empty/error responses is pre-existing. What changes here is that a successful late response after disposal now takes that path. At the base/initial commit, the same defined late response is incorrectly accepted but also reaches a tree refresh, releasing B's pagination.

Please keep the disposal guard and coordinate removed-provider pending-request cleanup with the pane's rendered loading state. Any cancellation/removal should preserve request identity so an old completion cannot remove a replacement request. A pane-level regression test with deferred A and surviving pageable B would cover this interaction; the new extension-host tests do not exercise it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please see inline comments

Remove disposed providers' pending requests before refreshing the pane so surviving providers can continue paging. Ignore completions that no longer own the pending request to protect replacement providers from stale results.
@SimonSiefke

Copy link
Copy Markdown
Contributor Author

Added 0ff1bd3 to try to properly dispose pending requests when timeline view gets disposed.

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Simon Siefke (@SimonSiefke) Thank you!

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Compile errors:
Warning: [eslint ] /mnt/vss/_work/vscode/vscode/src/vs/workbench/contrib/timeline/test/browser/timelinePane.test.ts: line 55, col 35, Warning - Use dot notation instead of bracket notation for property 'clear'. (local/code-no-bracket-notation-for-identifiers)
[eslint ]
[eslint ] Error: eslint failed with 12 warnings and/or errors
[eslint ] at eslint (file:///mnt/vss/_work/vscode/vscode/build/eslint.ts:49:9)
Warning: [eslint ] /mnt/vss/_work/vscode/vscode/src/vs/workbench/contrib/timeline/test/browser/timelinePane.test.ts: line 71, col 8, Warning - Use dot notation instead of bracket notation for property 'loadTimelineForSource'. (local/code-no-bracket-notation-for-identifiers)
Warning: [eslint ] /mnt/vss/_work/vscode/vscode/src/vs/workbench/contrib/timeline/test/browser/timelinePane.test.ts: line 80, col 8, Warning - Use dot notation instead of bracket notation for property 'loadTimelineForSource'. (local/code-no-bracket-notation-for-identifiers)
Warning: [eslint ] /mnt/vss/_work/vscode/vscode/src/vs/workbench/contrib/timeline/test/browser/timelinePane.test.ts: line 84, col 8, Warning - Use dot notation instead of bracket notation for property 'onProvidersChanged'. (local/code-no-bracket-notation-for-identifiers)
Warning: [eslint ] /mnt/vss/_work/vscode/vscode/src/vs/workbench/contrib/timeline/test/browser/timelinePane.test.ts: line 94, col 8, Warning - Use dot notation instead of bracket notation for property 'loadMore'. (local/code-no-bracket-notation-for-identifiers)
Warning: [eslint ] /mnt/vss/_work/vscode/vscode/src/vs/workbench/contrib/timeline/test/browser/timelinePane.test.ts: line 104, col 9, Warning - Use dot notation instead of bracket notation for property 'loadTimelineForSource'. (local/code-no-bracket-notation-for-identifiers)
Warning: [eslint ] /mnt/vss/_work/vscode/vscode/src/vs/workbench/contrib/timeline/test/browser/timelinePane.test.ts: line 105, col 9, Warning - Use dot notation instead of bracket notation for property 'onProvidersChanged'. (local/code-no-bracket-notation-for-identifiers)
Warning: [eslint ] /mnt/vss/_work/vscode/vscode/src/vs/workbench/contrib/timeline/test/browser/timelinePane.test.ts: line 109, col 9, Warning - Use dot notation instead of bracket notation for property 'onProvidersChanged'. (local/code-no-bracket-notation-for-identifiers)
Warning: [eslint ] /mnt/vss/_work/vscode/vscode/src/vs/workbench/contrib/timeline/test/browser/timelinePane.test.ts: line 111, col 9, Warning - Use dot notation instead of bracket notation for property 'refresh'. (local/code-no-bracket-notation-for-identifiers)
Warning: [eslint ] /mnt/vss/_work/vscode/vscode/src/vs/workbench/contrib/timeline/test/browser/timelinePane.test.ts: line 117, col 28, Warning - Use dot notation instead of bracket notation for property 'pendingRequests'. (local/code-no-bracket-notation-for-identifiers)
Warning: [eslint ] /mnt/vss/_work/vscode/vscode/src/vs/workbench/contrib/timeline/test/browser/timelinePane.test.ts: line 118, col 28, Warning - Use dot notation instead of bracket notation for property 'timelinesBySource'. (local/code-no-bracket-notation-for-identifiers)
Warning: [eslint ] /mnt/vss/_work/vscode/vscode/src/vs/workbench/contrib/timeline/test/browser/timelinePane.test.ts: line 125, col 32, Warning - Use dot notation instead of bracket notation for property 'timelinesBySource'. (local/code-no-bracket-notation-for-identifiers)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Compile errors

@SimonSiefke
Simon Siefke (SimonSiefke) marked this pull request as draft October 5, 2026 16:36
auto-merge was automatically disabled October 5, 2026 16:36

Pull request was converted to draft

The bracket-notation lint rule also rejects accesses to TypeScript private members. Expose the required member types through a test-only interface so the regression tests can use dot notation without changing the production API.
Register timeline providers with the suite disposable store so failed assertions still clean up. Verify the cached item resolves before disposal, and require the argument processor and timeline result instead of allowing missing setup to pass through optional access.
@SimonSiefke
Simon Siefke (SimonSiefke) marked this pull request as ready for review October 5, 2026 17:44
@SimonSiefke

Copy link
Copy Markdown
Contributor Author

Fixed some issues!

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 9f3d32f into microsoft:main Oct 5, 2026
35 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.142.0 milestone Oct 5, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-extHostTimeline branch October 13, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues timeline Timeline view issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants