Skip to content

comments: fix listener leak in mainThreadComments#312613

Merged
alexr00 merged 1 commit intomainfrom
roblou/agents/investigate-listener-leak-error
Apr 27, 2026
Merged

comments: fix listener leak in mainThreadComments#312613
alexr00 merged 1 commit intomainfrom
roblou/agents/investigate-listener-leak-error

Conversation

@roblourens
Copy link
Copy Markdown
Member

@roblourens roblourens commented Apr 26, 2026

Fixes #312612

Problem

onResourceHasCommentingRanges and onDidUpdateCommentThreads were subscribed inside $registerCommentController using this._register(), which appends to the class-level DisposableStore. 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 $registerCommentController instead of the constructor.

The subsequent March 2025 fixes (#243846, #244017) fixed other leaks in registerViewListeners but 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)

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>
Copilot AI review requested due to automatic review settings April 26, 2026 17:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 onResourceHasCommentingRanges subscription from $registerCommentController to the constructor.
  • Move onDidUpdateCommentThreads subscription from $registerCommentController to 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 alexr00 self-assigned this Apr 27, 2026
@alexr00 alexr00 marked this pull request as ready for review April 27, 2026 08:11
@alexr00 alexr00 enabled auto-merge (squash) April 27, 2026 08:11
@alexr00 alexr00 merged commit 8ff5242 into main Apr 27, 2026
30 checks passed
@alexr00 alexr00 deleted the roblou/agents/investigate-listener-leak-error branch April 27, 2026 08:11
@vs-code-engineering vs-code-engineering Bot added this to the 1.119.0 milestone Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

registerCommentController listener leak

3 participants