Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory leak in ModelSyncedEventEmitter #3510

Closed
lawmicha opened this issue Feb 9, 2024 · 5 comments
Closed

memory leak in ModelSyncedEventEmitter #3510

lawmicha opened this issue Feb 9, 2024 · 5 comments
Labels
bug Something isn't working datastore Issues related to the DataStore category

Comments

@lawmicha
Copy link
Member

lawmicha commented Feb 9, 2024

Also I found a small leak in ModelSyncedEventEmitter, you can find a patch for this here:
memoryLeak.patch

This memory leak might be better tracked by another issue but as the code to easily reproduce it is here, I let you organise this as you want.

Originally posted by @gbitaudeau in #3259 (comment)

Copy link

github-actions bot commented Feb 9, 2024

This issue was opened by a maintainer of this repository; updates will be posted here. If you are also experiencing this issue, please comment here with any relevant information so that we're aware and can prioritize accordingly.

@lawmicha lawmicha added bug Something isn't working datastore Issues related to the DataStore category labels Feb 9, 2024
@lawmicha
Copy link
Member Author

lawmicha commented Feb 9, 2024

diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/InitialSync/ModelSyncedEventEmitter.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/InitialSync/ModelSyncedEventEmitter.swift
index 9a44dbbc4..9bd806267 100644
--- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/InitialSync/ModelSyncedEventEmitter.swift
+++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/InitialSync/ModelSyncedEventEmitter.swift
@@ -65,7 +65,7 @@ final class ModelSyncedEventEmitter {
         self.syncOrchestratorSink = initialSyncOrchestrator?
             .publisher
             .receive(on: queue)
-            .filter(filterSyncOperationEvent(_:))
+            .filter { [weak self] in self?.filterSyncOperationEvent($0) ?? false }
             .sink(receiveCompletion: { _ in },
                   receiveValue: { [weak self] value in
                     self?.onReceiveSyncOperationEvent(value: value)
@@ -74,7 +74,7 @@ final class ModelSyncedEventEmitter {
         self.reconciliationQueueSink = reconciliationQueue?
             .publisher
             .receive(on: queue)
-            .filter(filterReconciliationQueueEvent(_:))
+            .filter { [weak self] in self?.filterReconciliationQueueEvent($0) ?? false }
             .sink(receiveCompletion: { _ in },
                   receiveValue: { [weak self] value in
                     self?.onReceiveReconciliationEvent(value: value)

@5d
Copy link
Member

5d commented May 3, 2024

Confirmed the memory leak does exist, and the proposed patch addresses and resolves the issue. Will created a PR for review and run tests.

@5d
Copy link
Member

5d commented May 17, 2024

The patch has been released in version 2.33.4. Closing this ticket.

@5d 5d closed this as completed May 17, 2024
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working datastore Issues related to the DataStore category
Projects
None yet
Development

No branches or pull requests

2 participants