-
Notifications
You must be signed in to change notification settings - Fork 112
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
Core Data: Make persistent container thread-safe #14534
Core Data: Make persistent container thread-safe #14534
Conversation
📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the improvement! I haven't found flaws in the code logic. As I understand, the only downside we could theoretically expect are longer load times for the app, since CoreDataManager
will be loaded all at once together with the persistent container.
We can observe in the subsequent releases if there are any dramatic changes in average (50th percentile) and longest (90th percentile) times in Xcode Organizer.
- I reproduced the issue with WooScreenshots not loading the stats data, and I can confirm that these changes help avoid the issue
- I tried stress testing the solution with some concurrent local unit tests and they succeeded
- I also performed smoke testing for login, logout, dashboard, orders, products, payments.
I haven't reproduced any new issues.
Do you remember why we had a lazy
persistent container in the first place? Were there any scenarios that we tried to cover and now we need to make sure they continue working as expected?
Thanks @staskus for the thorough reviews!
Honestly this code exists a few years before I joined, and I could not find any documentation about why the Core Data stack was built that way. My best guess is to optimize app start time as you pointed out. |
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
Closes: #14533
Description
When checking an issue with screenshot testing [p1732623939631369-slack-C03L1NF1EA3], @hichamboushaba found that the way we instantiate persistentContainer is not thread-safe as we can create it when accessing both
viewStorage
andwriterDerivedStorage
, which are in different threads.This PR updates
CoreDataManager
to be more thread-safe by making all lazy variables constants.Steps to reproduce
It's not easy to reproduce the race condition of persistent container. The most straightforward way is to run the screenshot test and verify that it is consistently able to display the stats on the dashboard.
Additionally, please do some quick smoke tests on the critical flows: Dashboard, Orders, Products, and Payments to ensure everything works as expected. You can follow the testing plan in pe5sF9-3e2-p2 as a guidance.
Testing information
Tested on simulator iPhone 16 Pro iOS 18 and confirmed that:
Screenshots
N/A
RELEASE-NOTES.txt
if necessary.Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: