firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.23k stars 565 forks source link

FirebaseCrashLytics java.lang.IllegalStateException: java.lang.RuntimeException: Bad file descriptor #6018

Closed Waleedasim closed 3 weeks ago

Waleedasim commented 3 weeks ago

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

I have an issue with Crashlytics. When I force a crash on the main thread as described in the documentation (on button click), I get the following exception:

 Error handling uncaught exception java.lang.IllegalStateException: java.lang.RuntimeException: Bad file descriptor at 

com.google.firebase.crashlytics.internal.common.Utils.awaitEvenIfOnMainThread(Utils.java:132) at 

com.google.firebase.crashlytics.internal.common.CrashlyticsController.handleUncaughtException(CrashlyticsController.java:255) 

at com.google.firebase.crashlytics.internal.common.CrashlyticsController.handleUncaughtException(CrashlyticsController.java:181) 

at com.google.firebase.crashlytics.internal.common.CrashlyticsController$1.onUncaughtException(CrashlyticsController.java:168) 

at com.google.firebase.crashlytics.internal.common.CrashlyticsUncaughtExceptionHandler.uncaughtException(CrashlyticsUncaughtE
xceptionHandler.java:54) at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068) 
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063) 
at java.lang.Thread.dispatchUncaughtException(Thread.java:1955) Caused by: java.lang.RuntimeException: Bad file descriptor at android.os.BinderProxy.transactNative(Native Method) at android.os.BinderProxy.transact(Binder.java:1136) 
at android.app.IActivityManager$Stub$Proxy.getRunningAppProcesses(IActivityManager.java:5335) 
at android.app.ActivityManager.getRunningAppProcesses(ActivityManager.java:3469) 
at com.google.firebase.crashlytics.internal.ProcessDetailsProvider.getAppProcessDetails(ProcessDetailsProvider.kt:37) 
at com.google.firebase.crashlytics.internal.ProcessDetailsProvider.getCurrentProcessDetails(ProcessDetailsProvider.kt:63) 
at com.google.firebase.crashlytics.internal.common.CrashlyticsReportDataCapture.populateEventApplicationData(CrashlyticsReportDataCapture.java:247)
 at com.google.firebase.crashlytics.internal.common.CrashlyticsReportDataCapture.captureEventData(CrashlyticsReportDataCapture.java:112)
 at com.google.firebase.crashlytics.internal.common.SessionReportingCoordinator.persistEvent(SessionReportingCoordinator.java:334) 
at com.google.firebase.crashlytics.internal.common.SessionReportingCoordinator.persistFatalEvent(SessionReportingCoordinator.java:131) 
at com.google.firebase.crashlytics.internal.common.CrashlyticsController$2.call(CrashlyticsController.java:214) 
at com.google.firebase.crashlytics.internal.common.CrashlyticsController$2.call(CrashlyticsController.java:199)
 at com.google.firebase.crashlytics.internal.common.CrashlyticsBackgroundWorker$3.then(CrashlyticsBackgroundWorker.java:105)
 at com.google.android.gms.tasks.zze.run(com.google.android.gms:play-services-tasks@@18.1.0:1)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
 at com.google.firebase.crashlytics.internal.common.ExecutorUtils$1$1.onRun(ExecutorUtils.java:67) 
at com.google.firebase.crashlytics.internal.common.BackgroundPriorityRunnable.run(BackgroundPriorityRunnable.java:27)

Steps to reproduce:

What happened? How can we make the problem occur? I am using Android 9 and have just integrated Crashlytics. I am using the latest Gradle plugin, Firebase BOM, and Crashlytics Gradle.

ext {
        kotlin_version = "1.9.23"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.4.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.4.2'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'kotlin-parcelize'
    id 'com.google.gms.google-services'
    id 'com.google.firebase.crashlytics'
}

dependencies {
    implementation(platform("com.google.firebase:firebase-bom:33.1.0"))
    implementation "com.google.firebase:firebase-crashlytics"
    implementation "com.google.firebase:firebase-analytics"
}

Relevant Code:

//This code works:
GlobalScope.launch(Dispatchers.IO) 
{
      throw RuntimeException("Test crash")
}

//This code doesn't works:

throw RuntimeException("Test crash")
google-oss-bot commented 3 weeks ago

I found a few problems with this issue:

lehcar09 commented 3 weeks ago

Hi @Waleedasim, thank you for reaching out. I tried reproducing the issue with the dependencies and code snippet you shared, however, I did not not encounter any exception in using only throw RuntimeException("Test crash").

Here's how I implement on button click:

        binding.button.setOnClickListener {
            throw RuntimeException("Test crash")

              //Also working
//            GlobalScope.launch(Dispatchers.IO)
//            {
//                throw RuntimeException("Test crash")
//            }
        }

Are you constantly experiencing this error? Or does the issue occur on certain devices and/or android versions? If by any chance, could you share an MCVE to help us investigate the issue? Thanks!

Waleedasim commented 3 weeks ago

Hi @lehcar09, Thanks for the quick reply.

Yes, I am always facing this issue, and I also tried it on Android 14, but the issue persists. I want to share the gradle file with you. How can I share it with you considering privacy concerns?

lehcar09 commented 3 weeks ago

If by any chance, can you share an MCVE? You just need to remove the google-services.json file and replace your application ID (if applicable).

I would suggest try using our quickstart app and make incremental changes to reproduce the issue.

You can share the Github repository link of your MCVE.

Waleedasim commented 3 weeks ago

@lehcar09 I have identified the issue, which lies within JNIHelp.

Below is the stack trace (the app has become unresponsive due to an overload of warnings on the main thread when crashed):

JNIHelp W Discarding pending exception (java.lang.StackOverflowError: stack size 8188KB) to throw java/lang/RuntimeException I believe this is the cause of the crash in Crashlytics.