Skip to content

Fix subscription cleanup leak in ReactiveNodeService #640

Closed

Description

@malibio

Summary

ReactiveNodeService has a subscription cleanup leak where subscribeAll() subscriptions are never unsubscribed when the viewer unmounts.

Background

Identified in the multi-tab reactivity investigation (Issue #631).

Current Behavior

Location: src/lib/services/reactive-node-service.svelte.ts:96

void _unsubscribe = sharedNodeStore.subscribeAll((nodeId, node) => {
  // ...
});

The _unsubscribe function is returned but never stored or called. When a viewer unmounts, the subscription remains active.

Impact

  • Memory leak: 1 subscription per mounted viewer accumulates
  • Example: Open/close same pane 100 times = 100 active subscriptions
  • All those subscriptions continue receiving callbacks, causing unnecessary processing

Acceptance Criteria

  • Store the unsubscribe function returned by subscribeAll()
  • Call unsubscribe when ReactiveNodeService is destroyed (onDestroy or cleanup function)
  • Add test verifying subscription is cleaned up on unmount
  • Verify no memory leak after repeated mount/unmount cycles

Recommended Solution

// In onMount or effect:
const unsubscribe = sharedNodeStore.subscribeAll((nodeId, node) => {
  // ...
});

// In onDestroy or return cleanup function:
return () => unsubscribe();

Priority

HIGH - Memory leak affects application stability over extended usage

Related

Metadata

Metadata

Assignees

Labels

bugfoundation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions