-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Gracefully handle WebView Crashes #5820
Gracefully handle WebView Crashes #5820
Conversation
Out of Memory issues in the WebView Renderer (e.g. large fonts) were causing the application to crash and restart, going to the deck browser. We catch the OOM using `onRenderProcessGone()` (API >= 26) and recreate the WebView to allow the application to continue with minor disruption. If a card has not been rendered, or if the same card fails twice, we fail gracefully and return to the deck browser.
454b1f7
to
9cc0244
Compare
AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java
Outdated
Show resolved
Hide resolved
Wow, this is great - the re-render attempt is a nice touch.
|
Likewise, it's a shame
I didn't see this when I studied. Theory: New card data is stored in The effect would be that the "new cards studied today" count is reset, not that reviews are being lost/undone.
Perfect! I chose a long toast, but the other options sound better. I'd like to turn this into a Will screenshot to confirm it's appropriate.
Sounds solid at first thought. |
Documentation states we should not try to clean up unrelated instances of WebViews. Returning false will cause a crash. Therefore return true to state that we don't need to crash.
@mikehardy Coming back to this as my next priority. What's the git strategy with review comments? Append + Squash merge, or should I rebase? |
It was an error which showed the card details (id). It's best to allow the user to explicitly dismiss it, as they may want to screenshot the details.
Sometimes, even after writing a handler, the application crashed. I believe that the C++ counts Java references when determining what to check when a WebView process dies. We perform a GC to ensure these are cleaned up by the time te C++ executes.
Review comments should be fixed, except
I feel there's minimal value in this. If we're in a crash loop, it won't need user input to trigger. It seems like added complexity for 1 less iteration of the crash loop before returning to the browser. That all being said, say the word and I'll do it. |
Yeah - you have a lot of plates spinning :)
In general we want a squeaky clean commit history. So when I'm working on AnkiDroid stuff I'm always doing rebase HEAD~N, fixing things, and re-force-pushing. For final merge if the commit history is really clean (via the above strategy) I just rebase and merge, if it's messy I squash and merge |
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.
2 nits and one testing remnant (I think) - but this is looking really good, I'm excited to merge this
AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java
Outdated
Show resolved
Hide resolved
Excellent - just waiting on CI then. I'm obviously motivated by crash stats at the moment, the impact this PR should have on the stats should be incredible, even with just the higher APIs supporting it. |
@mikehardy Do you have a list of most impactful crash bugs? Would be great to power through these over the next week. |
Honestly I will have to re-evaluate after this OOM fix, and the Custom Study Dialog fixes go out. It will take a week or so before I'm prepared to point at any issue now as I'm not sure there are any left that will have significant impact but it's hard to say. The last couple months has gotten almost all of them. If you really want to look at something impactful you might take on the zombiest issue of all time #1377 - a WYSIWYG editor mode. I'm sure there's a component for that somewhere (there has to be?) that can be bolted on? Not having the ability to do basic bold / underline / italic is a huge issue for many. |
User report - success!
|
Incidentally, this covers 58.6% of our userbase already (API26 / Android 8+) |
Purpose / Description
Out of Memory issues in the WebView Renderer (e.g. large fonts) were causing the application to crash and restart, going to the deck browser. This was listed as a soft crash in the bug report, but was actually killing the PID.
If a card fails once, we reset the WebView and try to render the card again.
If a card has not been rendered, or if the same card fails twice, we fail gracefully and return to the deck browser. We show a Toast to the user explaining that an OOM occurred.
Fixes
Fixes #5780
Approach
We catch the OOM using
onRenderProcessGone()
(API >= 26) and recreate the WebView to allow the application to continue with minor disruption.How Has This Been Tested?
Locally on my Android device (Android 9). Placing
crashWebViewRenderer()
insidedisplayCardAnswer()
Learning (optional, can help others)
StackOverflow example: https://stackoverflow.com/questions/46737984/onrenderprocessgonewebview-view-renderprocessgonedetail-detail-example
API: https://developer.android.com/reference/android/webkit/WebViewClient#onRenderProcessGone(android.webkit.WebView,%20android.webkit.RenderProcessGoneDetail)
https://developer.android.com/guide/webapps/managing-webview#termination-handle
https://chromium.googlesource.com/chromium/src/+/master/android_webview/browser/aw_browser_terminator.cc#93
Checklist
if
statements)Review Goals
inflateNewView
- doesn't feel like good code.