-
Notifications
You must be signed in to change notification settings - Fork 137
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
Fix crash when Exit event is fired multiple times #13281
Conversation
Exit event could potentially be fired more than once which will make the app crash because it will attempt to navigate back more than once leading to "IllegalStateException FragmentManager is already executing transactions"
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## trunk #13281 +/- ##
============================================
- Coverage 40.79% 40.79% -0.01%
Complexity 6411 6411
============================================
Files 1353 1353
Lines 77679 77679
Branches 10692 10692
============================================
- Hits 31690 31689 -1
- Misses 43182 43183 +1
Partials 2807 2807 ☔ View full report in Codecov by Sentry. |
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.
I couldn’t reproduce the issue either, and I’m not sure this will fix it because I didn’t notice the root cause being the invocation of .onBackPressed()
twice. There could be other reasons triggering a fragment manager transaction, but it’s worth trying. LGTM! 👍🏻
Thanks for the review @irfano
Hmm, that's a good point. However, from the code in those fragments experiencing the crash, I see only two events that would lead to a fragment transaction to be executed: |
Exit event could potentially be fired more than once, which will make the app crash because it will attempt to navigate back more than once, leading to "IllegalStateException FragmentManager is already executing transactions"
Closes: #13226
Closes: #13289
Description
Tentative fix for crash:
And for the crash:
Which has a similar stack trace.
I spent some time trying to replicate the crash but I was unable to. My hypothesis is that the
Exit
event is triggered simultaneously fromVariationDetailViewModel
when the user clicks the back button and whenloadVariation
function fails to load the variation and automatically runs:triggerEvent(Event.Exit)
. I tried using APIFaker to make different api calls fail when opening variation detail but wasn't able to reproduce the race condition where 2 Exit events are fired at once.The proposed solution is to basically make sure we unsubscribe from LiveData as soon as the first
Exit
event is fired, so that any subsequent call totriggerEvent(Event.Exit)
will be ignored.Testing information
Open a product with variations and check that everything works as expected:
The tests that have been performed
The above
RELEASE-NOTES.txt
if necessary. Use the "[Internal]" label for non-user-facing changes.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: