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

WIP: Fix ANR caused by operationRepo.enqueue while loading is in progress #2231

Closed
wants to merge 4 commits into from

Conversation

jinliu9508
Copy link
Contributor

@jinliu9508 jinliu9508 commented Dec 10, 2024

Description

One Line Summary

This PR will fix ANR caused by model store insertion while model store loading is stuck with some prolonged process.

Details

Motivation

Multiple users have reported that ANRs related to OneSignal have shown up in their analytics. We want to eliminate these ANRs to ensure smooth app start up.

Scope

This PR will alter the loading behavior for all models so that model insertion in the main thread becomes possible before loading is completed. The order will be correct because load() will insert cached items in the beginning of the list. However, it is possible for model to process the newly added item before loading is completed.

Others

This PR contains 4 commits.

  • The 1st commit forces a prolonged loading process for OperationModelStore and will cause an ANR during app startup.
  • The 2nd commit adds a test unit that will fail because of the long loading time added by the first commit.
  • The 3rd commit applies the fix and we should no longer observe the ANR and the test fail.
  • The 4th commit clears up the code that manually forces the loading process to take 5 seconds.

Testing

Unit testing

I have included a test unit to simulate a model insertion while loading is blocked by a lengthy process. THE UNIT TEST HAS ONE PENDING TODO.

Manual testing

The first commit manually force the loading of operationRepo to take at least 5 seconds in order to simulate the issue. The second commit applies the fix and we can observe that ANR can no long occur.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

@jinliu9508 jinliu9508 requested a review from jkasten2 December 10, 2024 17:41
@jinliu9508
Copy link
Contributor Author

I am not sure about this change: Do we really want the behavioral change for all models so that insertion is possible even the loading is not completed?

@jinliu9508 jinliu9508 force-pushed the fix-ANR-operationRepo-load branch from ed34602 to fecb45d Compare December 10, 2024 17:58
Copy link
Member

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

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

I think the change would introduce two issues:

  1. A concurrent modification exception could be thrown
  2. Operations could be added out of order

@jinliu9508 jinliu9508 closed this Dec 16, 2024
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.

2 participants