fix(sdk): prevent memory and CPU leaks on connection loss#178
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.