Skip to content

Fix deadlock when sending notification center in customerInfoListener#2407

Merged
aboedo merged 4 commits into
mainfrom
andy/sdk-3063-native-ios-sdk-4179-deadlock
Apr 14, 2023
Merged

Fix deadlock when sending notification center in customerInfoListener#2407
aboedo merged 4 commits into
mainfrom
andy/sdk-3063-native-ios-sdk-4179-deadlock

Conversation

@aboedo

@aboedo aboedo commented Apr 14, 2023

Copy link
Copy Markdown
Member

Fixes an issue where a deadlock could happen if you fire a notification in the customerInfoListener.

The issue stems from our usage of NotificationCenter to detect deletion of userDefaults.

Since we've changed the default UserDefaults anyway, I don't feel like this adds much value anymore, and we've spent wayyyy too much time dealing with race conditions caused by it, so I'm just getting rid of it.

I couldn't get it to reproduce on my device, but @codykerns was able to get a consistent repro and confirmed the fix with this branch.

@aboedo aboedo added the pr:fix A bug fix label Apr 14, 2023
@aboedo aboedo self-assigned this Apr 14, 2023
@aboedo

aboedo commented Apr 14, 2023

Copy link
Copy Markdown
Member Author

Swiftlint and I seriously disagree on what constitutes a "serious" violation 🙄

image

image

@aboedo aboedo requested review from a team and NachoSoto April 14, 2023 20:33
@aboedo aboedo marked this pull request as ready for review April 14, 2023 20:33

Logger.verbose(Strings.purchase.device_cache_init(self))

// Observe `UserDefaults` changes through `handleUserDefaultsChanged`

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this just used to detect if someone deletes RevenueCat data under the hood. It's saved us quite a few times, but still, now that we don't default to .standard, I don't think it adds that much value. And it's causing race conditions which have proven tricky to fix.

@NachoSoto NachoSoto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👏🏻

// Note: this should never use `self.userDefaults` directly because this method
// might be synchronized, and `Atomic` is not reentrant.
if self.cachedAppUserID != nil && Self.cachedAppUserID(userDefaults) == nil {
fatalError(Strings.purchase.cached_app_user_id_deleted.description)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this string can be deleted now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

good catch, deleted

@aboedo aboedo enabled auto-merge (squash) April 14, 2023 20:51
@aboedo aboedo merged commit eeb0ced into main Apr 14, 2023
@aboedo aboedo deleted the andy/sdk-3063-native-ios-sdk-4179-deadlock branch April 14, 2023 21:07
aboedo added a commit that referenced this pull request Apr 14, 2023
…#2407)

Fixes an issue where a deadlock could happen if you fire a notification
in the customerInfoListener.

The issue stems from our usage of NotificationCenter to detect deletion
of userDefaults.

Since we've changed the default UserDefaults anyway, I don't feel like
this adds much value anymore, and we've spent wayyyy too much time
dealing with race conditions caused by it, so I'm just getting rid of
it.

I couldn't get it to reproduce on my device, but @codykerns was able to
get a consistent repro and confirmed the fix with this branch.
@aboedo aboedo mentioned this pull request Apr 14, 2023
NachoSoto pushed a commit that referenced this pull request Apr 14, 2023
…#2407)

Fixes an issue where a deadlock could happen if you fire a notification
in the customerInfoListener.

The issue stems from our usage of NotificationCenter to detect deletion
of userDefaults.

Since we've changed the default UserDefaults anyway, I don't feel like
this adds much value anymore, and we've spent wayyyy too much time
dealing with race conditions caused by it, so I'm just getting rid of
it.

I couldn't get it to reproduce on my device, but @codykerns was able to
get a consistent repro and confirmed the fix with this branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants