Sentry Issue: WORDPRESS-ANDROID-3D6
RuntimeException: Using WebView from more than one process at once with the same data directory is not supported. https://crbug.com/558377
at org.wordpress.android.WordPress.getDefaultUserAgent(WordPress.java:623)
at org.wordpress.android.WordPress.getUserAgent(WordPress.java:654)
at org.wordpress.android.WordPress.onCreate(WordPress.java:262)
...
(14 additional frame(s) were not displayed)
RuntimeException: Unable to create application org.wordpress.android.WordPress: java.lang.RuntimeException: Using WebView from more than one process at once with the same data directory is not supported. https://crbug.com/558377
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6401)
at android.app.ActivityThread.access$1300(ActivityThread.java:248)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:216)
...
(4 additional frame(s) were not displayed)
Unable to create application org.wordpress.android.WordPress: java.lang.RuntimeException: Using WebView from more than one process at once with the same data directory is not supported. https://crbug.com/558377
90-day impact: ~2 per day
Users affected in the last 90 days: 95
Limited to: Android 9 & 10
https://sentry.io/share/issue/083fa51e0e30448694f0638e58f42906/
Sentry issue: WORDPRESS-ANDROID-3CW
90-day impact: ~8 per day
Users affected in the last 90 days: 390
Limited to: Android 9, 10
https://sentry.io/share/issue/083fa51e0e30448694f0638e58f42906/
90-day impact: ~74 per day
Users affected in the last 90 days: 3800
Limited to: Android 9
https://sentry.io/share/issue/c24b15bfbb884b44aece31bd07b29f9e/
Investigating this - this was a warning pre API 28 (Android 9) and is now a RuntimeException from Android 9 (P) and on https://developer.android.com/about/versions/pie/android-9.0-changes-28#web-data-dirs
Relevant discussion on the topic on Chromium site https://bugs.chromium.org/p/chromium/issues/detail?id=558377
I've been checking the WordPress Android source code to see if we're explicitly setting anything to work on a separate process and I couldn't find anything (i.e. in the Manifest). Given the crash happens in the Application's onCreate() method, I'm also doubting there would be another process running before the first attempt to run WebSettings.getDefaultUserAgent(getContext());.
Reading about how WebViews are handled, it seems there may be conditions wherer a WebView lives in one process and the renderer in another, as per what I could spot here https://developer.android.com/guide/webapps/managing-webview#termination-handle.
Hypothesis: maybe there was a previous (and differently caused) crash of the app, that left a different process running a WebView and now this second attempt to launch the app finds this and crashes? Going to look further.
Reopening since it seems the crash didn't disappear - crash on 13.6. Please verify it's the case before diving into the issue.
Users affected in the last 90 days: 4900
Limited to: Android 9
https://sentry.io/share/issue/c24b15bfbb884b44aece31bd07b29f9e/
Noting that https://github.com/wordpress-mobile/WordPress-Android/pull/10824 was released in 13.8 on 2019-12-16 and we should check on this one again at the next maintenance rotation.
Users affected in the last 90 days: 4200
Limited to: Android 9, Samsung
https://sentry.io/share/issue/c24b15bfbb884b44aece31bd07b29f9e/
Unfortunately this issue is still happening in the latest releases.
This issue seems to be occurring within the Android SDK itself and is being investigated in a follow-up issue by the Chromium team https://bugs.chromium.org/p/chromium/issues/detail?id=1054774
The summary is that there could be an error happening internally when the WebView is being initialized and the exception thrown at that time is captured and then initialization is tried again so this error occurs. The issue above has more details about this.
Thanks for the link @jd-alexander! That looks like a very new report and I am glad to see they are looking into it.
One interesting bit is this part:
To avoid this blowing up here, we could easily keep track of whether we had started initializing WebView and then explicitly throw an exception if we end up trying to initialize it a second time - this should at least make it clear to apps that they're doing something unsupported, and there's no safe way for us to continue anyhow (we have no idea which parts of init might not be idempotent).
In my previous exploration, I don't think I've seen something like this in our app, but I wasn't specifically looking for it, so I might not have noticed it. It might be a good idea to check if we are initializing the webview multiple times and try and fix that. Other than that, maybe we just follow that thread and see where it goes.
Good comment @oguzkocer
In my previous exploration, I don't think I've seen something like this in our app, but I wasn't specifically looking for it, so I might not have noticed it. It might be a good idea to check if we are initializing the
WebViewmultiple times and try and fix that. Other than that, maybe we just follow that thread and see where it goes.
Yes, I had a look and I also didn't notice the WebView being accessed multiple times during the Application initialization process, so it seems we indeed have to follow the thread.
67 events have been tracked for this crash in 14.6.1 since it was released 9d ago on Apr 22.
Number of users affected in the last 90d: 4,100
https://sentry.io/share/issue/c24b15bfbb884b44aece31bd07b29f9e/
155 events have been tracked for crash WORDPRESS-ANDROID-3CW in 14.7 and 14.7.1 since they were released 15d and 4d ago on May 15 and May 4 respectively.
Events in the last 90d: 25,000
Events in the last 15d for 14.7: 110
Events in the last 4d for 14.7.1: 45
Users affected in the last 90d: 3,500
Limited to: Android 9 and 10
Majority of: Samsung devices (with a few Redmi lurking)
https://sentry.io/share/issue/c24b15bfbb884b44aece31bd07b29f9e/
Update to add a graph for the last 90d, looks like it's trending downward but numbers are still decently high:

Events in the last 90d: 26,000
Users affected in the last 90d: 880
Limited to: Android 9 and 10
Majority of: mostly Redmi and Samsung
WORDPRESS-ANDROID-3CW: https://sentry.io/share/issue/c24b15bfbb884b44aece31bd07b29f9e/
Nice decrease from ~90d ago, but the issue is still happening in the latest stable release (15.3).
I tried to give this one a go, without much luck, but after checking the updated conversation on the issue, it looks like the Chromium team (or another relevant one) is actively working on mitigating the issue, that's why we probably see the decrease in cases. I assume that Redmi or Samsung might have some proprietary update mechanism for WebView, that's why the majority of the issues come from there.
Checking back in on this. I've caught up with the comments here and the comments on the bug's original thread - I don't think coming up with any elaborate workaround could help minimize the effects of this bug in particular, but maybe also bring other issues along with it. For example, I've thought of maybe refactoring the app's onCreate() method to do something in the background but return immediately (probably show a loading screen). I started playing around with this a bit (see https://github.com/wordpress-mobile/WordPress-Android/pull/13597). This could help our current fire up times anyway, and maybe (but only maybe) reduce the conditions in which the WebView lock is tried to be acquired twice by two app launches.
There were interesting points of view exchanged in this (now closed) draft PR https://github.com/wordpress-mobile/WordPress-Android/pull/13597, that I think provide a very good ground for an actual proper refactoring solution to take place in the future. For the future readers, I suggest you go and read the conversation there, with this comment in particular probably being the way to go when then time comes.
Events in the last 90d: 27,000
Users affected in the last 90d: 164
Limited to: Android 9 & 10
Culprit: android.app.ActivityThread in handleBindApplication
WORDPRESS-ANDROID-3CW: https://sentry.io/share/issue/c24b15bfbb884b44aece31bd07b29f9e/
Even though the overall event count from the last 90 days seem high, there are less than 200 users affected in the last 90 days and there were very few cases in the latest release which is 16.4 released 10 days ago on Jan 11. Recommend closing.
Most helpful comment
Checking back in on this. I've caught up with the comments here and the comments on the bug's original thread - I don't think coming up with any elaborate workaround could help minimize the effects of this bug in particular, but maybe also bring other issues along with it. For example, I've thought of maybe refactoring the app's onCreate() method to do something in the background but return immediately (probably show a loading screen). I started playing around with this a bit (see https://github.com/wordpress-mobile/WordPress-Android/pull/13597). This could help our current fire up times anyway, and maybe (but only maybe) reduce the conditions in which the WebView lock is tried to be acquired twice by two app launches.