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

Always call readyForPromotedProduct on main thread/actor #4613

Merged
merged 9 commits into from
Feb 3, 2025

Conversation

fire-at-will
Copy link
Contributor

@fire-at-will fire-at-will commented Dec 19, 2024

Motivation

Potential fix for #4582. While I haven't been able to reproduce the crash, a user on the issue has reported that this fixes the crash.

Description

#4582 describes an occasional crash that occurs when the SDK calls the PurchaseDelegate's readyForPromotedProduct function. The provided stacktraces show a threading issue occurring in both the SK1 & SK2 flows. Our working theory is that the calling code may expect readyForPromotedProduct to be called on the main thread/actor, and it is being called on a background thread.

This PR ensures that readyForPromotedProduct is always called on the Main Actor (for SK2) and main thread (for SK1).

A user on the GH Issue has reported that this PR resolves the crash for them.

SK1 & SK2 Differences

#4584 attempted to address this issue by always calling readyForPromotedProduct on the main actor, but we found that this caused very consistent, but still flaky, test failures in SK1 on iOS 14-16. Out of an abundance of caution, this was reverted in #4599.

This PR calls readyForPromotedProduct on the main thread instead of the main actor for SK1, which has addressed these test failures.

Testing

While I've been unable to reproduce the crash, I've tested the fix with both StoreKit 1 & 2 on iOS 17-18. I've been unable to test in iOS 15-16 because Xcode doesn't allow you to simulate Purchase Intents in simulators on iOS <17, and all of my physical devices are on iOS 18. That said, all automated tests pass on all iOS versions.

@fire-at-will
Copy link
Contributor Author

@RCGitBot please test

@fire-at-will fire-at-will added the pr:fix A bug fix label Dec 20, 2024
@fire-at-will
Copy link
Contributor Author

@RCGitBot please test

@fire-at-will
Copy link
Contributor Author

@RCGitBot please test

@fire-at-will
Copy link
Contributor Author

@RCGitBot please test

@fire-at-will
Copy link
Contributor Author

@RCGitBot please test

@fire-at-will
Copy link
Contributor Author

@RCGitBot please test

@fire-at-will fire-at-will marked this pull request as ready for review January 23, 2025 18:19
@fire-at-will fire-at-will changed the title [DO NOT MERGE] always call readyForPromotedProduct on main thread/actor Always call readyForPromotedProduct on main thread/actor Feb 3, 2025
@fire-at-will
Copy link
Contributor Author

@RCGitBot please test

@fire-at-will
Copy link
Contributor Author

@RCGitBot please test

switch self.systemInfo.storeKitVersion.effectiveVersion {
case .storeKit1:
// Calling the delegate method on the main actor causes test failures on iOS 14-16, so instead
// we dispatch to the main thread, which doesn't cause the failures.
Copy link
Member

Choose a reason for hiding this comment

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

yeah i think this is good practice anyway, specially if we're calling on the main actor in sk2

@fire-at-will fire-at-will merged commit 289ef64 into main Feb 3, 2025
10 checks passed
@fire-at-will fire-at-will deleted the 4582-potential-fix branch February 3, 2025 20:42
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