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/race condition after uninstalling app #383

Merged
merged 4 commits into from Nov 10, 2020

Conversation

aboedo
Copy link
Member

@aboedo aboedo commented Nov 6, 2020

Addresses #375

Fixes an issue where if the app modifies other userDefaults preferences, and the appUserID had never been set in RevenueCat, the SDK will crash.

@aboedo aboedo self-assigned this Nov 6, 2020
@aboedo aboedo requested a review from vegaro November 6, 2020 19:16
@aboedo aboedo added this to the 3.7.6 milestone Nov 6, 2020
@@ -109,6 +112,7 @@ - (void)clearCachesForAppUserID:(NSString *)oldAppUserID andSaveNewUserID:(NSStr
[self deleteAttributesIfSyncedForAppUserID:oldAppUserID];

[self cacheAppUserID:newUserID];
self.appUserIDHasBeenSet = YES;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this to cacheAppUserId? That way if another function calls that function, we won't forget to set this bool

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, good call. don't know what I was thinking.

@aboedo aboedo requested a review from vegaro November 9, 2020 14:53
@@ -99,7 +99,10 @@ - (nullable NSString *)cachedAppUserID {
}

- (void)cacheAppUserID:(NSString *)appUserID {
[self.userDefaults setObject:appUserID forKey:RCAppUserDefaultsKey];
@synchronized (self) {
self.appUserIDHasBeenSet = YES;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to move this right after the set in the userDefaults? Just in case it fails when calling setObject

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea! In practice, I don't think we're actually catching the error anywhere so it'd crash, but if we did add a try / catch this would lead to an inconsistent state.
Updated.

@aboedo aboedo merged commit f5da81a into develop Nov 10, 2020
@aboedo aboedo deleted the fix/race_condition_after_uninstalling_app branch November 10, 2020 16:52
@aboedo aboedo mentioned this pull request Nov 11, 2020
@aboedo aboedo mentioned this pull request Jul 13, 2021
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.

None yet

2 participants