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

[Crash] Fix crash when searching products in order product selector #14095

Merged
merged 3 commits into from
Oct 2, 2024

Conversation

rachelmcr
Copy link
Contributor

@rachelmcr rachelmcr commented Oct 2, 2024

Closes: #14085

Description

This fixes a crash caused by fetching products from storage while updating them in the same context on a background thread. This happened while performing a product search in the order form product selector (while adding products to an order).

This also includes a small improvement to the local search, to return results with partial matches to the search term (similar to the remote search method) instead of only exact matches.

How

  • Instead of using sharedDerivedStorage (which is storageManager.writerDerivedStorage, meant for writing to storage and used for background updates) we now use storageManager.viewStorage to fetch the products.
  • The local search predicate now uses CONTAINS instead of LIKE (to return partial matches).

Steps to reproduce

Note: I was only able to get the app to crash in the simulator. I couldn't reproduce this crash on a device, but as the simulator crash indicates this action is not thread safe.

  1. Build and run the app.
  2. Go to the Orders tab.
  3. Tap "+" to create a new order.
  4. Tap "Add Products".
  5. Search for a product. Notice that it crashes on _PFAssertSafeMultiThreadedAccess_impl.

Testing information

Test with the same steps as above in this branch and confirm it doesn't crash.

Additional testing:

  1. Build and run the app with Xcode 16.
  2. Go to the Orders tab.
  3. Tap "+" to create a new order.
  4. Tap "Add Products".
  5. Search for a product using a partial match (e.g. Card when you have a product called Gift Card in the first page of results) and confirm the match is loaded from storage.

Screenshots

Screencast demonstrates the following search scenarios:

  • Local results (full match to product name)
  • Local results (partial match) + remote results added
  • No local results + remote results added
  • No local results & no remote results
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2024-10-02.at.17.01.49.mp4

  • I have considered if this change warrants user-facing release notes and have added them to 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:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on all devices (phone/tablet) and no regressions are added.

@rachelmcr rachelmcr added the type: crash The worst kind of bug. label Oct 2, 2024
@rachelmcr rachelmcr added this to the 20.7 milestone Oct 2, 2024
@dangermattic
Copy link
Collaborator

1 Warning
⚠️ This PR is assigned to the milestone 20.7. This milestone is due in less than 2 days.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr14095-957c6d1
Version20.6
Bundle IDcom.automattic.alpha.woocommerce
Commit957c6d1
App Center BuildWooCommerce - Prototype Builds #11093
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@rachelmcr rachelmcr merged commit a131756 into trunk Oct 2, 2024
14 checks passed
@rachelmcr rachelmcr deleted the issue/14085-fix-product-cache-search-crash branch October 2, 2024 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: crash The worst kind of bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NSGenericException: *** Collection <__NSCFSet: 0x301cd2d60> was mutated while being enumerated.
3 participants