Skip to content

fix(sdk): prevent memory and CPU leaks on connection loss#178

Merged
mremond merged 3 commits intomainfrom
fix/memory
Feb 13, 2026
Merged

fix(sdk): prevent memory and CPU leaks on connection loss#178
mremond merged 3 commits intomainfrom
fix/memory

Conversation

@mremond
Copy link
Member

@mremond mremond commented Feb 13, 2026

Store and call cleanup functions for store subscriptions and side effects in XMPPClient.destroy(). Previously, these unsubscribe functions were discarded, causing subscriptions to accumulate and leak memory/CPU when connections were lost or intermittent.

Store and call cleanup functions for store subscriptions and side
effects in XMPPClient.destroy(). Previously, these unsubscribe
functions were discarded, causing subscriptions to accumulate and
leak memory/CPU when connections were lost or intermittent.

Changes:
- Store cleanup functions from setupPresenceSync, createStoreBindings,
  and setupStoreSideEffects in XMPPClient
- Call all cleanup functions in destroy() method
- Add MUC.cleanup() to clear pending join timeouts on disconnect
- Clear typing timeouts when going offline to prevent orphaned timers
presenceActor.subscribe() returns a Subscription object, not a
function. Wrap it in an arrow function to match cleanupFunctions
type signature.
- Fix TS2345: wrap XState Subscription in arrow function for
  cleanupFunctions type compatibility
- Extract setupBindings() from constructor so bindings can be
  re-established after destroy()
- Split cleanup into bindingCleanupFunctions (rebindable: store
  bindings, side effects, presence sync) and cleanupFunctions
  (constructor-only: presence persistence)
- XMPPProvider now calls setupBindings/destroy in useEffect,
  supporting StrictMode's mount/cleanup/remount cycle
@mremond mremond merged commit 9f029d6 into main Feb 13, 2026
1 check passed
@mremond mremond deleted the fix/memory branch February 13, 2026 08:27
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.

1 participant