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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Use weak reference in ReaderCardService #22644

Merged
merged 1 commit into from
Feb 20, 2024

Conversation

dvdchr
Copy link
Contributor

@dvdchr dvdchr commented Feb 20, 2024

Fixes #22640

The ReaderCardsStreamViewController may be already deallocated once the service object completes fetching, causing it to access an invalid unowned reference to self.

This fixes the issue by using a weak reference. With this, when the view controller deallocates early, we'll return Error.noInterests instead of crashing. For more investigation notes, refer to the description in #22640.

To test

Unfortunately, there's no sure way to reproduce the issue. However, based on the breadcrumbs available in Sentry, and the notes from the description in #22640, we can deduce a possible "path" to the crash:

Case 1: Trigger the Reader onboarding screen

  • You can either create a new account or unsubscribe from all tags and then restart the app.
  • Launch the Jetpack app.
  • Select the Reader tab.
  • Go to the Discover stream (if you're not already there). The tag selection screen should appear.
  • Select several tags to subscribe, then press the primary button on the bottom.
  • 馃攷 Verify that the Discover stream now displays a list of posts without crashing.

Case 2: Spam-switch the Reader stream

  • It might be good to use a slow network connection in this case. Or simulate it with Network Link Conditioner.
  • Launch the Jetpack app.
  • Select the Reader tab.
  • From the Discover tab, quickly switch between the streams (e.g. Discover > Subscriptions > Discover > Saved).
  • 馃攷 Verify that the app does not crash.

Regression Notes

  1. Potential unintended areas of impact
    Should be none. Change is minimal.

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    Manually tested the changes.

  3. What automated tests I added (or what prevented me from doing so)
    N/A. ReaderCardService is retained in ReaderCardsStreamViewController, and this bug happens on a race condition where the view controller is deallocated (for example because of switching to a different stream) before the fetch completes. This makes it rather tricky to unit test. Refactoring it now is also not feasible as this is part of a legacy code.

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.

Testing checklist:

  • WordPress.com sites and self-hosted Jetpack sites.
  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • VoiceOver.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn鈥檛 complete, formatting should still respect the right-to-left layout)
  • iPhone and iPad.
  • Multi-tasking: Split view and Slide over. (iPad)

@dangermattic
Copy link
Collaborator

1 Warning
鈿狅笍 PR is not assigned to a milestone.

Generated by 馃毇 Danger

@wpmobilebot
Copy link
Contributor

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 Numberpr22644-9918e56
Version24.2.1
Bundle IDorg.wordpress.alpha
Commit9918e56
App Center BuildWPiOS - One-Offs #8871
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

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 Numberpr22644-9918e56
Version24.2.1
Bundle IDcom.jetpack.alpha
Commit9918e56
App Center Buildjetpack-installable-builds #7901
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

Copy link
Contributor

@wargcm wargcm left a comment

Choose a reason for hiding this comment

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

I didn't see any issue with either test case. LGTM! :shipit:

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.

Fatal error: Attempted to read an unowned reference in ReaderCardService.fetch
4 participants