Skip to content

fix(tree): Fix event buffer leak#27434

Open
Josmithr wants to merge 8 commits into
microsoft:mainfrom
Josmithr:tree/fix-event-buffer-leak
Open

fix(tree): Fix event buffer leak#27434
Josmithr wants to merge 8 commits into
microsoft:mainfrom
Josmithr:tree/fix-event-buffer-leak

Conversation

@Josmithr
Copy link
Copy Markdown
Contributor

@Josmithr Josmithr commented May 28, 2026

Updates internal withBufferedEvents to simplify its state management to not leverage event listeners, and to ensure that nodes are not leaked.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 28, 2026

Hi! Thank you for opening this PR. Want me to review it?

Based on the diff (109 lines, 2 files), I've queued these reviewers:

  • Correctness — logic errors, race conditions, lifecycle issues
  • Security — vulnerabilities, secret exposure, injection
  • API Compatibility — breaking changes, release tags, type design
  • Performance — algorithmic regressions, memory leaks
  • Testing — coverage gaps, hollow tests

How this works

  • Adjust the reviewer set by ticking/unticking boxes above. Reviewer toggles alone don't trigger anything.

  • Tick Start review below to dispatch the review fleet.

  • After review finishes, tick Start review again to request another run — it auto-resets after each dispatch.

  • This comment updates as new commits land; your reviewer selections are preserved.

  • Start review

@Josmithr Josmithr marked this pull request as ready for review May 28, 2026 20:14
@Josmithr Josmithr requested a review from a team as a code owner May 28, 2026 20:14
@Josmithr Josmithr requested review from CraigMacomber and Copilot May 28, 2026 20:14
Comment thread packages/dds/tree/src/simple-tree/core/treeNodeKernel.ts Outdated
Comment thread packages/dds/tree/src/simple-tree/core/treeNodeKernel.ts Outdated
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 memory leak in treeNodeKernel where every KernelEventBuffer permanently subscribed to a module-level flushEventsEmitter, keeping the buffer (and everything its listeners captured) alive for the lifetime of the module even if its owning TreeNodeKernel was dropped without being explicitly disposed. The fix replaces the global emitter with an activeBuffers Set that buffers only opt-in during an active withBufferedTreeEvents window and is drained when the window ends.

Changes:

  • Replace flushEventsEmitter subscription with a module-level activeBuffers: Set<KernelEventBuffer> populated only while buffering is active.
  • Snapshot-and-clear activeBuffers in withBufferedTreeEvents finally to safely support reentrant calls, and remove the per-instance flush listener / its disposer in KernelEventBuffer.dispose.
  • Expose a test-only TEST_activeBufferCount and add regression tests covering baseline, unbuffered, and nested windows.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/dds/tree/src/simple-tree/core/treeNodeKernel.ts Switch from global flush emitter to opt-in activeBuffers Set; rework dispose; add test accessor.
packages/dds/tree/src/test/simple-tree/core/treeNodeKernel.spec.ts Add regression tests asserting no buffer retention after/outside/nested buffering windows.

Comment thread packages/dds/tree/src/simple-tree/core/treeNodeKernel.ts Outdated
Comment thread packages/dds/tree/src/simple-tree/core/treeNodeKernel.ts Outdated
Josmithr added 3 commits May 28, 2026 13:24
Co-authored-by: Joshua Smithrud <54606601+Josmithr@users.noreply.github.com>
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.

2 participants