Skip to content

fix: memory leak in file search listeners - #345781

Merged
Dmitriy Vasyura (dmitrivMS) merged 2 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-search-listeners
Nov 5, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 2 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-search-listeners

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

Each cached file search subscribes its progress callback to the cached row. Completed searches leave that callback subscribed, and cancellation listeners also stay registered after the search finishes. Reusing one cache keeps adding callbacks for completed requests.

Change

Dispose progress and cancellation subscriptions when each search promise settles.

Before

Alternating two file queries in the same Quick Open picker for 37 runs adds 74 fileProgressCallback closures and their result callbacks in the extension host:

before

After

No more leak detected.

Test Video

search-listener-churn-quarter-speed.webm

AI disclosure: Model: unknown. Worktime: unknown

Copilot AI balanced review requested due to automatic review settings November 3, 2026 10:35

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.

🟢 Approval recommended

No active review issues are recorded for the listener-cleanup change.

No open issues 🎉

What changed in this PR

This PR fixes listener retention in VS Code’s file search service by disposing subscriptions when search promises settle, preventing completed requests from accumulating callbacks.

Changes:

  • Dispose cached-search progress and cancellation listeners on completion or failure.
  • Dispose engine cancellation listeners when searches settle.
  • Add regression tests for cached-search listener cleanup and cancellation after completion.
File Description
src/​vs/​workbench/​services/​search/​test/​node/​rawSearchServiceListeners.test.ts Adds listener-cleanup and post-completion cancellation tests.
src/​vs/​workbench/​services/​search/​node/​rawSearchService.ts Disposes progress and cancellation subscriptions using promise finalizers.

Review effort: Balanced

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.

🟢 Approval recommended

No active review issues remain for the search-listener cleanup change, though tests were not run during this review.

No open issues 🎉

Review effort: Max

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Simon Siefke (@SimonSiefke) Thank you!

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit aa049ba into microsoft:main Nov 5, 2026
59 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.146.0 milestone Nov 5, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-search-listeners branch November 5, 2026 11:28
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 search Search widget and operation issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants