comments: fix listener leak in mainThreadComments#312613
Merged
Conversation
onResourceHasCommentingRanges and onDidUpdateCommentThreads were subscribed in $registerCommentController using this._register(), which appends to the class-level DisposableStore. Each call to $registerCommentController (one per comment provider extension) added a new pair of permanent listeners, causing unbounded accumulation. Both listeners only call registerView(), which is idempotent, and have no per-controller dependency. Move them to the constructor so they're registered exactly once. This regression was introduced by f64aa51 ("Comments panel appears without having GHPR installed") which changed from eager view registration to lazy/event-driven, but accidentally put the subscriptions in a per-controller method. The lazy behavior is registerView() still only fires when comments actually exist.preserved Fixes a regression of #243841. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a listener leak in MainThreadComments by ensuring comment-service event subscriptions are registered exactly once per MainThreadComments instance (instead of once per registered comment controller), preserving lazy comments view registration.
Changes:
- Move
onResourceHasCommentingRangessubscription from$registerCommentControllerto the constructor. - Move
onDidUpdateCommentThreadssubscription from$registerCommentControllerto the constructor. - Keep
registerView()as the single, idempotent entry point for lazy comments view registration.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/api/browser/mainThreadComments.ts | Registers comment-service listeners once in the constructor to prevent unbounded listener accumulation when multiple controllers are registered. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
alexr00
approved these changes
Apr 27, 2026
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.
Fixes #312612
Problem
onResourceHasCommentingRangesandonDidUpdateCommentThreadswere subscribed inside$registerCommentControllerusingthis._register(), which appends to the class-levelDisposableStore. Each call to$registerCommentController— one per comment provider extension — permanently added a new pair of listeners, causing unbounded accumulation. With enough extensions (or extension host restarts), this hits the global leak warning threshold of 175.Root cause
The regression was introduced by f64aa51 (#242550, "Comments panel appears without having GHPR installed"). That change correctly made view registration lazy (event-driven rather than eager), but accidentally placed the event subscriptions in
$registerCommentControllerinstead of the constructor.The subsequent March 2025 fixes (#243846, #244017) fixed other leaks in
registerViewListenersbut missed this one.Fix
Move both listeners to the constructor, where they're registered exactly once. The lazy behavior from #242550 is fully preserved —
registerView()is still only called when comments actually exist, and it contains its own idempotency guard (getViewDescriptorById).(Written by Copilot)