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

fix(DataStore): Add 'weak self' to prevent retain cycles in OutgoingMutationQueue #3429

Merged
merged 2 commits into from
Dec 20, 2023

Conversation

lawmicha
Copy link
Member

@lawmicha lawmicha commented Dec 19, 2023

Issue #

#3325

Description

The crash in the issue above points to OutgoingMutationQueue.swift:142

self.operationQueue.isSuspended = false

In this PR, we're addressing strong reference cycles in OutgoingMutationQueue by adding weak self. Calls to Amplify.DataStore.stop() will deintialize RemoteSyncEngine, which holds a single instance of the OutgoingMutationQueue. It's likely that OutgoingMutationQueue (self) is deallocated before one of the closures that have strong reference to self is executed. Then later, when it executes, it tries to access the deallocated self and crashes

General Checklist

  • Added new tests to cover change, if needed
  • Build succeeds with all target using Swift Package Manager
  • All unit tests pass
  • All integration tests pass
  • Security oriented best practices and standards are followed (e.g. using input sanitization, principle of least privilege, etc)
  • Documentation update for the change if required
  • PR title conforms to conventional commit style
  • New or updated tests include Given When Then inline code documentation and are named accordingly testThing_condition_expectation()
  • If breaking change, documentation/changelog update with migration instructions

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@lawmicha lawmicha requested a review from a team as a code owner December 19, 2023 20:39
@lawmicha lawmicha changed the title fix(DataStore): Add 'weak self' to prevent retain cycles fix(DataStore): Add 'weak self' to prevent retain cycles in OutgoingMutationQueue Dec 19, 2023
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0211104) 68.09% compared to head (29180f4) 68.09%.
Report is 5 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3429   +/-   ##
=======================================
  Coverage   68.09%   68.09%           
=======================================
  Files        1086     1086           
  Lines       36304    36306    +2     
=======================================
+ Hits        24721    24724    +3     
+ Misses      11583    11582    -1     
Flag Coverage Δ
API_plugin_unit_test 67.07% <ø> (ø)
AWSPluginsCore 64.38% <ø> (ø)
Amplify 48.17% <ø> (-0.02%) ⬇️
Analytics_plugin_unit_test 81.16% <ø> (ø)
Auth_plugin_unit_test 79.07% <ø> (ø)
CoreMLPredictions_plugin_unit_test 59.44% <ø> (ø)
DataStore_plugin_unit_test 80.95% <100.00%> (+0.03%) ⬆️
Geo_plugin_unit_test 70.75% <ø> (ø)
Logging_plugin_unit_test 63.09% <ø> (ø)
Predictions_plugin_unit_test 37.29% <ø> (ø)
PushNotifications_plugin_unit_test 87.03% <ø> (ø)
Storage_plugin_unit_test 78.10% <ø> (ø)
unit_tests 68.09% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lawmicha lawmicha merged commit 006e045 into main Dec 20, 2023
76 checks passed
@lawmicha lawmicha deleted the lawmicha.fix-outgoing-queue branch December 20, 2023 14:28
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.

3 participants