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

Fixed ServiceWorker Initialization Issue #3880

Merged
merged 2 commits into from
Jun 15, 2024
Merged

Fixed ServiceWorker Initialization Issue #3880

merged 2 commits into from
Jun 15, 2024

Conversation

MohitMaliFtechiz
Copy link
Collaborator

@MohitMaliFtechiz MohitMaliFtechiz commented Jun 13, 2024

Fixes #3878

Thanks to @Popolechien for sharing this crash report in #3600 (comment)

  • ServiceWorker was being initialized every time the CoreApp instance was created. When the application crashed, ErrorActivity was invoked to send a crash report, running in a separate process. In this new process, the ServiceWorker was also being initialized.

  • Upon user interaction (e.g., clicking "No Thanks" to relaunch the app), the application returned to the main process, leading to a second initialization of the ServiceWorker with the same data directory, causing a crash.

  • Since ErrorActivity does not require any WebView-related functionality, it is unnecessary to initialize the ServiceWorker in this process.

  • The fix involves modifying the initialization code to ensure the ServiceWorker is only initialized in the main process of the application.

  • In this crash report see the lock owner is error_activity, and the current process is org.kiwix.kiwixmobile.

       Caused by: 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 org.kiwix.kiwixmobile (pid 22073), lock owner 
       org.kiwix.kiwixmobile:error_activity (pid 21360)

Full logs:

06-12 22:49:30.853 22073 22073 E AndroidRuntime: Process: org.kiwix.kiwixmobile, PID: 22073
06-12 22:49:30.853 22073 22073 E AndroidRuntime: java.lang.ExceptionInInitializerError
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at org.kiwix.kiwixmobile.core.di.components.DaggerCoreComponent$CoreComponentImpl.inject(DaggerCoreComponent.java:23)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at org.kiwix.kiwixmobile.core.CoreApp.onCreate(CoreApp.kt:104)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1266)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7619)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2400)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:106)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at android.os.Looper.loopOnce(Looper.java:226)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:313)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:8762)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: Caused by: 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 org.kiwix.kiwixmobile (pid 22073), lock owner org.kiwix.kiwixmobile:error_activity (pid 21360)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at org.chromium.android_webview.AwDataDirLock.b(chromium-TrichromeWebViewGoogle6432.aab-stable-642216533:201)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at org.chromium.android_webview.AwBrowserProcess.j(chromium-TrichromeWebViewGoogle6432.aab-stable-642216533:16)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at com.android.webview.chromium.L.d(chromium-TrichromeWebViewGoogle6432.aab-stable-642216533:203)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at com.android.webview.chromium.L.b(chromium-TrichromeWebViewGoogle6432.aab-stable-642216533:42)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at com.android.webview.chromium.WebViewChromiumFactoryProvider.getServiceWorkerController(chromium-TrichromeWebViewGoogle6432.aab-stable-642216533:22)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at android.webkit.ServiceWorkerController.getInstance(ServiceWorkerController.java:57)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at androidx.webkit.internal.ApiHelperForN.getServiceWorkerControllerInstance(ApiHelperForN.java:1)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at androidx.webkit.internal.ServiceWorkerControllerImpl.<init>(ServiceWorkerControllerImpl.java:9)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	at androidx.webkit.ServiceWorkerControllerCompat$LAZY_HOLDER.<clinit>(ServiceWorkerControllerCompat.java:3)
06-12 22:49:30.853 22073 22073 E AndroidRuntime: 	... 13 more
  • Initializing the ServiceWorker in the onCreate method of the CoreApp class so that all necessary application setup is complete before the service worker is initialized and provides better control over the initialization sequence.

@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as draft June 13, 2024 10:18
Copy link

codecov bot commented Jun 13, 2024

Codecov Report

Attention: Patch coverage is 37.50000% with 5 lines in your changes missing coverage. Please review.

Project coverage is 53.55%. Comparing base (14b782a) to head (4c3af12).
Report is 1 commits behind head on main.

Files Patch % Lines
...kiwix/kiwixmobile/core/ServiceWorkerInitialiser.kt 28.57% 0 Missing and 5 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3880      +/-   ##
============================================
+ Coverage     53.53%   53.55%   +0.02%     
- Complexity     1398     1401       +3     
============================================
  Files           301      301              
  Lines         11564    11569       +5     
  Branches       1523     1526       +3     
============================================
+ Hits           6191     6196       +5     
+ Misses         4377     4374       -3     
- Partials        996      999       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as ready for review June 13, 2024 13:08
* ServiceWorker was being initialized every time the `CoreApp` instance was created. When the application crashed, `ErrorActivity` was invoked to send a crash report, running in a separate process. In this new process, the ServiceWorker was also being initialized.
* Upon user interaction (e.g., clicking "No Thanks" to relaunch the app), the application returned to the main process, leading to a second initialization of the ServiceWorker with the same data directory, causing a crash.
* Since `ErrorActivity` does not require any WebView-related functionality, it is unnecessary to initialize the ServiceWorker in this process.
* The fix involves modifying the initialization code to ensure the ServiceWorker is only initialized in the main process of the application.
…s so that all necessary application setup is complete before the service worker is initialized and provides better control over the initialization sequence.
@kelson42 kelson42 merged commit 9f94965 into main Jun 15, 2024
9 of 10 checks passed
@kelson42 kelson42 deleted the Fixes#3878 branch June 15, 2024 11:15
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

Successfully merging this pull request may close these issues.

ServiceWorker mgmt seems instable
3 participants