fix(tree): Fix event buffer leak#27434
Conversation
|
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:
How this works
|
There was a problem hiding this comment.
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
flushEventsEmittersubscription with a module-levelactiveBuffers: Set<KernelEventBuffer>populated only while buffering is active. - Snapshot-and-clear
activeBuffersinwithBufferedTreeEventsfinallyto safely support reentrant calls, and remove the per-instance flush listener / its disposer inKernelEventBuffer.dispose. - Expose a test-only
TEST_activeBufferCountand 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. |
Co-authored-by: Joshua Smithrud <54606601+Josmithr@users.noreply.github.com>
…thr/FluidFramework into tree/fix-event-buffer-leak
Updates internal
withBufferedEventsto simplify its state management to not leverage event listeners, and to ensure that nodes are not leaked.