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

Do not instantiate the Runtime in crash reporter service #259

Closed
wants to merge 2 commits into from

Conversation

svillar
Copy link
Member

@svillar svillar commented Sep 8, 2022

Currently the CrashReporter service uses the runtime to create a CrashReportIntent. The reason why it does that is because the CrashReportIntent receives some parameters that depend on the backend (Gecko,Chromium) which cannot be resolved at build time.

By the time the CrashReporter creates that intent the runtime might not exist (like after a crash in the application). This means that the service will try to create it. The problem is that creating the runtime might not be possible, for example the GeckoRuntime must be created in the main thread but the crash reporter service is run in an async task as it can be see in this backtrace:

2022-09-08 14:15:38.005 20233-20267/com.igalia.wolvic.dev E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.igalia.wolvic.dev:crash, PID: 20233
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$4.done(AsyncTask.java:399)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
Caused by: java.lang.IllegalThreadStateException: Expected thread 2 ("main"), but running on thread 930 ("AsyncTask #1")
at org.mozilla.gecko.util.ThreadUtils.assertOnThreadComparison(ThreadUtils.java:127)
at org.mozilla.gecko.util.ThreadUtils.assertOnThread(ThreadUtils.java:93)
at org.mozilla.gecko.util.ThreadUtils.assertOnUiThread(ThreadUtils.java:84)
at org.mozilla.geckoview.GeckoRuntime.create(GeckoRuntime.java:552)
at com.igalia.wolvic.browser.api.impl.RuntimeImpl.(RuntimeImpl.java:72)
at com.igalia.wolvic.browser.api.WFactory.createRuntime(WFactory.java:14)
at com.igalia.wolvic.browser.engine.EngineProvider.getOrCreateRuntime(EngineProvider.kt:67)
at com.igalia.wolvic.crashreporting.CrashReporterService.onHandleWork(CrashReporterService.java:65)
at androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:392)
at androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:383)
at android.os.AsyncTask$3.call(AsyncTask.java:378)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
at java.lang.Thread.run(Thread.java:919) 

This is why we have to add an extra class per backend that is able to create those intents without having to instantiate the runtime.

@svillar
Copy link
Member Author

svillar commented Aug 1, 2023

Let's retake this later

@svillar svillar closed this Aug 1, 2023
@HollowMan6 HollowMan6 reopened this Oct 1, 2023
@HollowMan6 HollowMan6 marked this pull request as ready for review October 1, 2023 21:04
@HollowMan6
Copy link
Collaborator

HollowMan6 commented Oct 1, 2023

Should resolve #1029

Now it looks like it's fixed, as I can see in the log that Crash reporter job finished. Although I'm not sure about how to avoid the ForegroundServiceDidNotStartInTimeException here:

2023-10-01 23:05:57.684  1887-2183  VRB[CrashR...erService] com.igalia.wolvic                    D  Content process crash Intent { act=org.mozilla.gecko.ACTION_CRASHED cmp=com.igalia.wolvic/.browser.api.impl.CrashReporterServiceImpl (has extras) }
2023-10-01 23:05:57.686  1887-2183  VRB[CrashR...erService] com.igalia.wolvic                    D  Crash reporter job finished
2023-10-01 23:06:05.433  1887-1887  AndroidRuntime          com.igalia.wolvic                    D  Shutting down VM
2023-10-01 23:06:05.437  1887-1887  AndroidRuntime          com.igalia.wolvic                    E  FATAL EXCEPTION: main
                                                                                                    Process: com.igalia.wolvic:crash, PID: 1887
                                                                                                    android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{a582c46 u0 com.igalia.wolvic/.browser.api.impl.CrashReporterServiceImpl}
                                                                                                    	at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:1986)
                                                                                                    	at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:1957)
                                                                                                    	at android.app.ActivityThread.access$2700(ActivityThread.java:259)
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2211)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:214)
                                                                                                    	at android.os.Looper.loop(Looper.java:304)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:7909)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1010)
2023-10-01 23:06:05.442  1887-1887  Process                 com.igalia.wolvic                    I  Sending signal. PID: 1887 SIG: 9

@HollowMan6
Copy link
Collaborator

@HollowMan6
Copy link
Collaborator

cc: @svillar in case you haven't aware that this is reopened.

Copy link
Collaborator

@HollowMan6 HollowMan6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-approve

svillar and others added 2 commits March 22, 2024 10:55
Currently the CrashReporter service uses the runtime to create a
CrashReportIntent. The reason why it does that is because the CrashReportIntent
receives some parameters that depend on the backend (Gecko,Chromium) which
cannot be resolved at build time.

By the time the CrashReporter creates that intent the runtime might not exist
(like after a crash in the application). This means that the service will try
to create it. The problem is that creating the runtime might not be possible,
for example the GeckoRuntime must be created in the main thread but the crash
reporter service is run in an async task as it can be see in this backtrace:

2022-09-08 14:15:38.005 20233-20267/com.igalia.wolvic.dev E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
    Process: com.igalia.wolvic.dev:crash, PID: 20233
    java.lang.RuntimeException: An error occurred while executing doInBackground()
        at android.os.AsyncTask$4.done(AsyncTask.java:399)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
        at java.util.concurrent.FutureTask.run(FutureTask.java:271)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
     Caused by: java.lang.IllegalThreadStateException: Expected thread 2 ("main"), but running on thread 930 ("AsyncTask #1")
        at org.mozilla.gecko.util.ThreadUtils.assertOnThreadComparison(ThreadUtils.java:127)
        at org.mozilla.gecko.util.ThreadUtils.assertOnThread(ThreadUtils.java:93)
        at org.mozilla.gecko.util.ThreadUtils.assertOnUiThread(ThreadUtils.java:84)
        at org.mozilla.geckoview.GeckoRuntime.create(GeckoRuntime.java:552)
        at com.igalia.wolvic.browser.api.impl.RuntimeImpl.<init>(RuntimeImpl.java:72)
        at com.igalia.wolvic.browser.api.WFactory.createRuntime(WFactory.java:14)
        at com.igalia.wolvic.browser.engine.EngineProvider.getOrCreateRuntime(EngineProvider.kt:67)
        at com.igalia.wolvic.crashreporting.CrashReporterService.onHandleWork(CrashReporterService.java:65)
        at androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:392)
        at androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:383)
        at android.os.AsyncTask$3.call(AsyncTask.java:378)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:919) 

This is why we have to add an extra class per backend that is able to create
those intents without having to instantiate the runtime.

Signed-off-by: Songlin Jiang <sjiang@igalia.com>
@svillar
Copy link
Member Author

svillar commented May 16, 2024

Abandoning. We've already landed a couple of patches mitigating this issue.

@svillar svillar closed this May 16, 2024
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.

Make the CrashReporterService work again Modernize deprecated JobIntentService
2 participants