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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.RuntimeException: Using WebView from more than one process at once with the same data directory is not supported. #20

Closed
stezan opened this issue Jan 13, 2022 · 10 comments

Comments

@stezan
Copy link

stezan commented Jan 13, 2022

After updating the SDK version to the 2.5.1, we got some crashes related to this https://crbug.com/558377.
The problems in brief is that in some situations some processes try to access WebView through the same directory, that is not possible on the Android platform. Probably the bug was introduced after the fix of this issue #19.

Here the log of the crash

Unable to create application com.app.Application: java.lang.RuntimeException: Using WebView from more than one process at once with the same data directory is not supported. https://crbug.com/558377 : Current process com.application.package (pid 27676), lock owner com.application.package (pid 24841)


java.lang.RuntimeException: Using WebView from more than one process at once with the same data directory is not supported. https://crbug.com/558377 : Current process com.moneyfarm.moneyfarm (pid 27676), lock owner com.moneyfarm.moneyfarm (pid 24841)
    at org.chromium.android_webview.AwDataDirLock.b
    at EB0.g
    at EB0.b
    at EB0.i
    at com.android.webview.chromium.WebViewChromiumFactoryProvider.h
    at com.android.webview.chromium.WebViewChromium.init
    at android.webkit.WebView.<init>(WebView.java:435)
    at android.webkit.WebView.<init>(WebView.java:355)
    at android.webkit.WebView.<init>(WebView.java:337)
    at android.webkit.WebView.<init>(WebView.java:324)
    at android.webkit.WebView.<init>(WebView.java:314)
    at com.adform.adformtrackingsdk.web.AdWebView.<init>(AdWebView.java:31)
    at com.adform.adformtrackingsdk.AdformTrackingSdk.createWebView(AdformTrackingSdk.java:133)
    at com.adform.adformtrackingsdk.AdformTrackingSdk.loadHandler(AdformTrackingSdk.java:111)
    at com.adform.adformtrackingsdk.AdformTrackingSdk.startTracking(AdformTrackingSdk.java:76)

    at com.ourapplication.core.facilities.implementations.AdformFacility.startTracking(AdformFacility.kt:90)
    at com.ourapplication.core.facilities.implementations.AdformFacility.<init>(AdformFacility.kt:69)
    at com.ourapplication.core.facilities.FacilitiesManager$Companion.init(FacilitiesManager.kt:34)
    at com.ourapplication.Application.onCreate(Application.kt:57)

    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1208)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7024)
    at android.app.ActivityThread.access$1700(ActivityThread.java:274)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2098)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:233)
    at android.app.ActivityThread.main(ActivityThread.java:8068)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)

We are not able to find any workaround, do you have any suggestion on how to solve this?

@stezan stezan changed the title RuntimeException android.app.ActivityThread in handleBindApplication java.lang.RuntimeException: Using WebView from more than one process at once with the same data directory is not supported. Jan 13, 2022
@marius-m
Copy link
Contributor

marius-m commented Jan 13, 2022

Investigation

Hi, thanks for your inquiry. You are absolutely correct. We did try to attempt to fix the problem, but it seems it’s not so straightforward 🤔.

I have a couple of ideas how to try to approach this, however it will take a bit of time of testing to release a new version. I’m thinking of giving access to SDK user access to change this directory during runtime and making it unique for the SDK itself.

Whenever its ready, I would love to hear from you if the fix has lifted your app issue.

More about the problem

You can read more about the problem here.

Also, to change cache directory for a webview is to use this

WebView.setDataDirectorySuffix(processNameSuffix);

Seems like, whoever is using the webview in the app, are using the same cache directory that is created. And also, we’re not the only ones that are using webview for our data loading behavior.

@stezan
Copy link
Author

stezan commented Jan 13, 2022

@marius-m I tried to fix as you reported, but I think that it could cause an unexpected application size growth, because it creates new folder, what do you think?

@marius-m
Copy link
Contributor

Yeah I agree. We had this behavior reported before. Let me take a bit of time to take a look and test out. I'm thinking of creating "unique enough" directory, that maybe it would not cause problem for multiple processes, but static enough for the app to do a clean-up itself. Maybe that'll solve it 🤔

@marius-m
Copy link
Contributor

Bugfix summary

Okay, after a bit of investigation and testing, I was not able to replicate, crash the app using multiple processes in DemoApp using Adform tracking SDK. However, I did apply some changes for the project itself that may solve your issue or at very least push us forward in the investigation itself. All the changes are available in 2.5.2 version.

  • Changed the webView data dir suffix to be a bit more custom when creating a webview As we’re using WebView to send our data, we still need app’s webview instance to send the data. So just before its creation, it should target a bit more custom.
  • By using AdformTrackingSdk.setDebugModeEnabled(true) you should see what kind of directory is bound just before WebView creation.
  • Also enabled an accessor to change custom WebView dir change binding. So by using AdformTrackingSdk.setWebviewDataDirSuffix("custom_dir") just before AdformTrackingSdk.startTracking(this, Constants.TRACK_POINT_ID) it will bind a different directory of your choosing.

Hopefully, these ’tools’ should be enough to solve your issue.

Please ping me if you’re still experiencing any issues. If so, could you create a ’DemoApp’, where it replicates your situation and app crashes? This would help me immensely to proceed with this issue.

@stezan
Copy link
Author

stezan commented Jan 25, 2022

Hello @marius-m I tried the new version of the SDK (2.5.2) on my app and I still get some crashes on our Sentry... Unfortunately I am not able to replicate the crash on my devices/emulators

@marius-m
Copy link
Contributor

Hmm, I'm a bit confused. So you're getting crashes reported to Sentry, but cannot replicate the crash on the device? Could it be, that sentry gets reports from an older version, which does not have the fixes?

@stezan
Copy link
Author

stezan commented Jan 25, 2022

The crash was introduced in the 2.5.1 Adform SDK release and is present also in 2.5.2, I am getting the crash using 2.5.2
The crash log is there #20 (comment)

I am not able to replicate it because it probably involves some activity recreation and is difficult to reproduce

@marius-m
Copy link
Contributor

Is your app using different processes to access those directories from webview?
I'm guessing the culprit may be a mix of libraries that you're using or how they are used (For instance, using services or launching activities with spawning separate processes). And the Adform library is crashing as only a side effect.

With the newer version, I've introduced a method that lets you change the data directory manually, however, I doubt this will solve the problem.

It is hard for us to replicate the problem as there multiple variations that may not be working. I'd suggest trying out to isolate and replicate the problem first. Create a new empty project and put in libraries that your app is using or how it is using. I'm guessing it should not be a problem to replicate a problem, as this crash is caused in initialization phase. If you'll be able to catch it, then we could try taking a further look.

@giovanniPolatoO
Copy link

Hi, in my project I still have report of this crash. Are there news?

@rolandasito
Copy link
Collaborator

It looks like in some edge cases, Android start a new process for the application when it thinks that a previous instance of your app's process has been killed but is actually still hanging around, causing there to be two copies of your app process at the same time.

We have added random string also for the data directory suffix. It should fix this issue or reduce crash repetitions significantly.

Changes are in 2.5.4 version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants