-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Use local post ID in HistoryList to fix TransactionTooLargeException #10240
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
Conversation
Usage of background threads will be applied later on.
To minimize regressions, use uiDispatcher as the default coroutine dispatcher. This is because HistoryViewModel has assumptions in some of its routines that it is running on the main thread.
Keeping the post in the `Bundle` adds to the Editor’s saved instance for state restoration. Storing the local post id only decreases the size of the saved instance. Therefore, decreasing the chances of TransactionTooLargeException exceptions.
An “empty” UI will be shown for now. It’s unlikely to have a `null` post so I think this is good enough.
WordPress/src/test/java/org/wordpress/android/viewmodel/history/HistoryViewModelTest.kt
Outdated
Show resolved
Hide resolved
WordPress/src/test/java/org/wordpress/android/viewmodel/history/HistoryViewModelTest.kt
Outdated
Show resolved
Hide resolved
WordPress/src/test/java/org/wordpress/android/viewmodel/history/HistoryViewModelTest.kt
Outdated
Show resolved
Hide resolved
WordPress/src/test/java/org/wordpress/android/viewmodel/history/HistoryViewModelTest.kt
Outdated
Show resolved
Hide resolved
2fc9967 to
3ebf364
Compare
WordPress/src/main/java/org/wordpress/android/viewmodel/history/HistoryViewModel.kt
Show resolved
Hide resolved
malinajirka
left a comment
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.
Good job @shiki! Thanks for diving into this and for the great description ❤️.
I did some regressions test of the History fragment and everything worked as expected. However, I wasn't able to reproduce the crash on any of my devices/emulators. The EditPostActivity either never loads (black screen or frozen editor screen) or it doesn't crash. Having said that, I've encountered the TransactionTooLargeException in many other applications and I'm positive this fix will solve it (We still store SiteModel into a Bundle at a lot of places, but it shouldn't be that big hopefully).
WordPress/src/main/java/org/wordpress/android/ui/posts/HistoryListFragment.kt
Show resolved
Hide resolved
|
@malinajirka Thank you for spending the time to test this!
That's weird. And no errors in the logs too?
Thanks for confirming that. This is the first time I've seen and fixed an error like this. 😄
Right. I looked at them and they weren't that big. Is it worth it to create an issue for it? I responded to your concern. Please let me know if I merge this. 🙂 |
Yep, no errors. I have encountered some segmentation fault in C code once, but the log wasn't very helpful and I wasn't able to reproduce it.
I don't think it's necessary to fix them. We just need to make sure we don't introduce the same issue in any new code. I know we have discussed this issue about a year ago, so hopefully at least most people should be aware that it's not a best practice to store potentially huge objects into Bundles. Thank you though;)! Looks good to me. Thank you, great job! |
Fixes #9685 and #5456.
Findings
When I edit a post with 300K words and put the app to the background, the app will consistently crash.
Using toolargetool, I found that the
EditPostActivity'sBundlegrows as thePostModelcontents grows. At 2000 words:At 5000 words:
I honed in on the
android:support:fragmentswhich grows similarly. Digging deeper, I found thatHistoryListFragmentbundles akey_postobject which is aPostModel. At 2000 words:And at 5000 words:
If the post contents is even bigger, we would hit the
Bundlesize limit.Solution
This PR changes the
HistoryListFragmentso it will only accept a local post ID and it handles the loading of thePostModelitself in the background. When the state is saved, only the local post ID will be saved. TheEditPostActivityandroid:support:fragmentsobject no longer grows and stays at about19.1KB.Editing the post with 300K words no longer crashes. It takes 5 seconds to load like always but that is currently not the focus of this fix. I tested this with a post that has a lot of images and embedded Youtube videos and I have not observed any crashes.
Other Changes
Since the
HistoryListFragmentnow only has the local post id, I added a simple routine for the unlikely scenario where thePostModelcannot be loaded. The history page will show an empty view.Testing
History List
Please do a regression test for the revision history like:
All the existing features should still work without problems.
TransactionTooLargeException
Please also test if you will still receive a
TransactionTooLargeExceptioncrash after this change. There are reproduction steps in the linked issues like:I found that the most consistent way I will receive the crash is:
The crash happens after this.
Reviewing
Only 1 reviewer is needed but anyone can review.
Release Notes
RELEASE-NOTES.txt.