Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #8109: Don't call fetch promotions on uninitialized rewards services #8110

Merged
merged 1 commit into from
Sep 20, 2023

Conversation

kylehickinson
Copy link
Collaborator

Calling rewards engine APIs before the engine has been initialized can cause a crash because the WhenReady method used inside RewardsEngineImpl will queue up what is assumed a SingleThreadedTaskRunner. This is not the case for iOS which uses a standard sequenced task runner.

This call to fetch promotions happens when showing the rewards panel but the rewards engine may not be initialized until the panel is shown (a sec/privacy requirement to not make API calls to rewards services until a user interacts with the feature), so it was being scheduled instead of executing immediately, thus hitting the threading issue on the brave-core side

Summary of Changes

This pull request fixes #8109

Submitter Checklist:

  • Unit Tests are updated to cover new or changed functionality
  • User-facing strings use NSLocalizableString()
  • New or updated UI has been tested across:
    • Light & dark mode
    • Different size classes (iPhone, landscape, iPad)
    • Different dynamic type sizes

Reviewer Checklist:

  • Issues include necessary QA labels:
    • QA/(Yes|No)
    • bug / enhancement
  • Necessary security reviews have taken place.
  • Adequate unit test coverage exists to prevent regressions.
  • Adequate test plan exists for QA to validate (if applicable).
  • Issue and pull request is assigned to a milestone (should happen at merge time).

Calling rewards engine APIs before the engine has been initialized can cause a crash because the `WhenReady` method used inside `RewardsEngineImpl` will queue up what is assumed a `SingleThreadedTaskRunner`. This is not the case for iOS which uses a standard sequenced task runner.

This call to fetch promotions happens when showing the rewards panel but the rewards engine may not be initialized until the panel is shown (a sec/privacy requirement to not make API calls to rewards services until a user interacts with the feature), so it was being scheduled instead of executing immediately, thus hitting the threading issue on the brave-core side
@kylehickinson kylehickinson added this to the 1.59 milestone Sep 20, 2023
@kylehickinson kylehickinson requested a review from a team as a code owner September 20, 2023 15:07
@kylehickinson kylehickinson enabled auto-merge (squash) September 20, 2023 15:08
@kylehickinson kylehickinson merged commit 5160b5c into development Sep 20, 2023
@kylehickinson kylehickinson deleted the rewards-1.59.x-crash-fix branch September 20, 2023 15:38
arthuredelstein pushed a commit to brave/brave-core that referenced this pull request Feb 13, 2024
…d rewards services (brave/brave-ios#8110)

Calling rewards engine APIs before the engine has been initialized can cause a crash because the `WhenReady` method used inside `RewardsEngineImpl` will queue up what is assumed a `SingleThreadedTaskRunner`. This is not the case for iOS which uses a standard sequenced task runner.

This call to fetch promotions happens when showing the rewards panel but the rewards engine may not be initialized until the panel is shown (a sec/privacy requirement to not make API calls to rewards services until a user interacts with the feature), so it was being scheduled instead of executing immediately, thus hitting the threading issue on the brave-core side
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash when opening the rewards panel the first time in a fresh install
2 participants