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

Blaze: Update blaze instance from the correct thread #20413

Merged
merged 2 commits into from
Mar 29, 2023

Conversation

momo-ozawa
Copy link
Contributor

Fixes #20397

Description

Fixes an issue where Blog managed object was being updated from the wrong thread.

Queries the Blog managed object using the context provided by the performAndSave closure to ensure the managed object is updated correctly.

Ref: pbArwn-602-p2

How to test

  1. Switch to trunk
  2. Add -com.apple.CoreData.ConcurrencyDebug 1 to your launch arguments
  3. Build and run the Jetpack app
  4. The app crashes

Screenshot 2023-03-27 at 11 52 23

  1. Switch to this branch
  2. Build and run the Jetpack app
  3. The app doesn't crash

Regression Notes

  1. Potential unintended areas of impact
    n/a

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    n/a

  3. What automated tests I added (or what prevented me from doing so)
    n/a

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@peril-wordpress-mobile
Copy link

Warnings
⚠️ This PR is assigned to a milestone which is closing in less than 4 days Please, make sure to get it merged by then or assign it to a later expiring milestone

Generated by 🚫 dangerJS

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 27, 2023

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr20413-20eddd8
Version22.0
Bundle IDorg.wordpress.alpha
Commit20eddd8
App Center BuildWPiOS - One-Offs #5344
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 27, 2023

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr20413-20eddd8
Version22.0
Bundle IDcom.jetpack.alpha
Commit20eddd8
App Center Buildjetpack-installable-builds #4371
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.


guard let blog = context.object(with: objectID) as? Blog else {
DDLogError("Unable to update isBlazeApproved value for blog")
completion?()
Copy link
Contributor

Choose a reason for hiding this comment

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

The completion block can't be called here, otherwise it'll cause the same issue in #20196.

Copy link
Contributor

Choose a reason for hiding this comment

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

An alternative would be declaring contextManager as CoreDataStackSwift, so that you can catch the error thrown by the Core Data operation closure:

contextManager.performAndSave({ context in
    let blog = try context.existingObject(with: objectID) as! Blog
    blog.isBlazeApproved = isBlazeApproved
}, completion: { (result: Result<Void, Error>) in
    completion?()
}, on: .main)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The completion block can't be called here

Fixed! 20eddd8

We're only logging the error, so I decided to use guard let blog = try? ...

blog.isBlazeApproved = isBlazeApproved
DDLogInfo("Successfully updated isBlazeApproved value for blog: \(isBlazeApproved)")

}, completion: {
completion?()
Copy link
Contributor

Choose a reason for hiding this comment

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

This completion block will be called regardless if the Core Data operation in the closure above success or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the desired behavior - I've amended the documentation to clarify this 🙇‍♀️

@momo-ozawa momo-ozawa requested a review from crazytonyli March 28, 2023 14:10
Copy link
Contributor

@hassaanelgarem hassaanelgarem left a comment

Choose a reason for hiding this comment

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

The changes look good to me, and it works as described 🚀

@mokagio
Copy link
Contributor

mokagio commented Mar 29, 2023

Taking over merge to ship a new beta

@mokagio mokagio merged commit 6373391 into release/22.0 Mar 29, 2023
@mokagio mokagio deleted the fix/20397-blaze-core-data branch March 29, 2023 05:26
@mokagio mokagio mentioned this pull request Mar 29, 2023
4 tasks
@hypest
Copy link
Contributor

hypest commented Apr 3, 2023

Thank you for the fix @momo-ozawa !

Can you add a link to a convo with context about going with a beta fix instead, for example, of a hotfix? Thanks!

@momo-ozawa
Copy link
Contributor Author

@hypest 👋

We didn't have a conversation about whether to do a betafix vs hotfix for this crash. Sorry - I should have checked in with the release rotation team! Since this crash affected ~0.05% of users (low impact), and this isn't a critical flow (medium severity), I figured this would be a betafix instead of a hotfix.

Sentry Issue: JETPACK-IOS-Z5

@hypest
Copy link
Contributor

hypest commented Apr 3, 2023

Thanks for elaborating @momo-ozawa !

Since this crash affected ~0.05% of users (low impact), and this isn't a critical flow (medium severity), I figured this would be a betafix instead of a hotfix.

Makes sense.

To try to understand the impact, I wonder, are the users affected all on the Blaze flow, or some may be on an irrelevant flow? If all on the Blaze flow, would all Blaze flow users encounter the issue? I would elevate the impact assessment depending on those questions.

For the severity assessment part, I wonder if the issue has been a blocker for the Blaze users for, say, reaching the check-out stage. If yes, I'd elevate the severity here as well.

I understand that the fix will be out with the 22.0 release scheduled for today so, no further action needed, but I think we probably want to update the crash priority matrix, to include the new revenue flows, the least.

@momo-ozawa
Copy link
Contributor Author

@hypest Those are good points, thanks for sharing.

To try to understand the impact, I wonder, are the users affected all on the Blaze flow, or some may be on an irrelevant flow?

If all on the Blaze flow, would all Blaze flow users encounter the issue?

For the severity assessment part, I wonder if the issue has been a blocker for the Blaze users for, say, reaching the check-out stage

This crash can happen when assessing whether users are eligible for Blaze. So this is before users begin the blaze purchase flow. Also, it doesn't happen all the time.

I think we probably want to update the crash priority matrix, to include the new revenue flows, the least.

Agreed! I've updated the crash priority matrix to include this info. pbArwn-1gZ-p2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants