Repository navigation
Fix subscription cleanup leak in ReactiveNodeService - #645
Conversation
## Changes - Store the unsubscribe function from `subscribeAll()` in a trackable variable - Add `destroy()` method to ReactiveNodeService that calls the unsubscribe function - Call `destroy()` in NodeServiceContext's onDestroy lifecycle hook ## Impact - Prevents 1 subscription per mount from accumulating - Fixes memory leak when opening/closing panes repeatedly - No more unnecessary callback processing from orphaned subscriptions ## Testing - Added 7 new tests verifying cleanup behavior: - destroy() properly cleans up subscription - destroy() is safe to call multiple times - No memory leak after 100 mount/unmount cycles - Callbacks stop firing after destroy() - Subscription accumulation prevention tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Code Review Report - PR #645Review Type: Initial Review Summary AssessmentThis PR fixes a genuine memory leak in ReactiveNodeService where Requirements Check (Issue #640)
All acceptance criteria satisfied. Code Review FindingsCritical IssuesNone identified. Suggested Improvements1. [Improvement] Consider clearing pending debounced operations on destroy() 📁 The destroy() {
if (_subscriptionUnsubscribe) {
_subscriptionUnsubscribe();
_subscriptionUnsubscribe = null;
}
// Consider: Clear all debounced operations
// for (const [nodeId] of debouncedOperations) {
// cleanupDebouncedOperations(nodeId);
// }
// debouncedOperations.clear();
}Rationale (YAGNI Consideration): This is a minor concern for this PR's scope. The debounced operations have short timeouts (300ms, 2000ms) and the callbacks check if the node exists before proceeding. Marking as suggestion for future consideration. 2. [Nit] JSDoc could mention idempotency guarantee 📁 The JSDoc mentions it "MUST be called" but doesn't mention that it's safe to call multiple times. The tests verify this behavior, but documenting it in the JSDoc would be helpful: /**
* Cleanup method to prevent subscription memory leaks.
* MUST be called when the service instance is no longer needed (e.g., on component unmount).
* Safe to call multiple times (idempotent).
* Failing to call this will result in subscription accumulation and unnecessary processing.
*/NitpicksNit: Test file has mock setup that could be shared 📁 The Svelte 5 rune mocks are repeated from other test files. Consider extracting to a shared test helper for consistency. However, this is a common pattern across the codebase, so not blocking. Architecture & Design Assessment
Testing Assessment
Security AssessmentNo security concerns - this is internal state management with no external inputs. Performance Assessment✅ Positive Impact - Prevents subscription accumulation which would cause O(n) callback processing where n = mount count. Test Results Verification
Final Recommendation✅ APPROVE This PR demonstrates excellent engineering practice:
The suggested improvements are minor polish and do not block merge. 🤖 Review generated with Claude Code |
malibio
left a comment
There was a problem hiding this comment.
Reviewer Recommendation: APPROVE - Clean, well-tested fix for subscription memory leak. All acceptance criteria met. See detailed review comment above for minor suggestions.
Added "Safe to call multiple times (idempotent)" to the destroy() method documentation, as suggested in code review. Addresses reviewer recommendation from PR #645. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Review Feedback AddressedSummary of Changes: ✅ Addressed (1 recommendation)
⏭️ Skipped (2 recommendations)
Commits: 1 ( 🤖 Generated with Claude Code |
* Fix subscription cleanup leak in ReactiveNodeService (closes #640) ## Changes - Store the unsubscribe function from `subscribeAll()` in a trackable variable - Add `destroy()` method to ReactiveNodeService that calls the unsubscribe function - Call `destroy()` in NodeServiceContext's onDestroy lifecycle hook ## Impact - Prevents 1 subscription per mount from accumulating - Fixes memory leak when opening/closing panes repeatedly - No more unnecessary callback processing from orphaned subscriptions ## Testing - Added 7 new tests verifying cleanup behavior: - destroy() properly cleans up subscription - destroy() is safe to call multiple times - No memory leak after 100 mount/unmount cycles - Callbacks stop firing after destroy() - Subscription accumulation prevention tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address review: Add idempotency documentation to destroy() JSDoc Added "Safe to call multiple times (idempotent)" to the destroy() method documentation, as suggested in code review. Addresses reviewer recommendation from PR #645. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
* Fix subscription cleanup leak in ReactiveNodeService (closes #640) ## Changes - Store the unsubscribe function from `subscribeAll()` in a trackable variable - Add `destroy()` method to ReactiveNodeService that calls the unsubscribe function - Call `destroy()` in NodeServiceContext's onDestroy lifecycle hook ## Impact - Prevents 1 subscription per mount from accumulating - Fixes memory leak when opening/closing panes repeatedly - No more unnecessary callback processing from orphaned subscriptions ## Testing - Added 7 new tests verifying cleanup behavior: - destroy() properly cleans up subscription - destroy() is safe to call multiple times - No memory leak after 100 mount/unmount cycles - Callbacks stop firing after destroy() - Subscription accumulation prevention tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address review: Add idempotency documentation to destroy() JSDoc Added "Safe to call multiple times (idempotent)" to the destroy() method documentation, as suggested in code review. Addresses reviewer recommendation from PR #645. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
* Fix subscription cleanup leak in ReactiveNodeService (closes #640) ## Changes - Store the unsubscribe function from `subscribeAll()` in a trackable variable - Add `destroy()` method to ReactiveNodeService that calls the unsubscribe function - Call `destroy()` in NodeServiceContext's onDestroy lifecycle hook ## Impact - Prevents 1 subscription per mount from accumulating - Fixes memory leak when opening/closing panes repeatedly - No more unnecessary callback processing from orphaned subscriptions ## Testing - Added 7 new tests verifying cleanup behavior: - destroy() properly cleans up subscription - destroy() is safe to call multiple times - No memory leak after 100 mount/unmount cycles - Callbacks stop firing after destroy() - Subscription accumulation prevention tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address review: Add idempotency documentation to destroy() JSDoc Added "Safe to call multiple times (idempotent)" to the destroy() method documentation, as suggested in code review. Addresses reviewer recommendation from PR #645. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Summary
subscribeAll()subscriptions were never unsubscribed when viewer unmountsdestroy()method to ReactiveNodeService for proper cleanupProblem
ReactiveNodeService had a subscription cleanup leak where
subscribeAll()subscriptions were never unsubscribed when the viewer unmounts (Issue #640).Impact:
Solution
subscribeAll()destroy()method that calls unsubscribe when service is no longer neededdestroy()in NodeServiceContext'sonDestroycallbackTest plan
destroy()properly cleans up subscriptiondestroy()is safe to call multiple timesdestroy()Test Results
Baseline (before changes): Frontend: 1424 passed, 3 failed
After changes: Frontend: 1431 passed, 3 failed (+7 new tests, same failures)
Closes #640
🤖 Generated with Claude Code