MindscapeHQ/raygun4android

StackOverflow exceptions/crashes not reported by Raygun

rs146 opened this issue · 4 comments

rs146 commented

Hi,

We have noticed that Raygun doesn't seem to pick up any crashes caused by StackOverflow errors. For example, we have the following stack trace in our Play Console:

java.lang.StackOverflowError: 
  at androidx.core.view.ViewCompat.getLayoutDirection (ViewCompat.java:1558)
  at androidx.drawerlayout.widget.DrawerLayout.findDrawerWithGravity (DrawerLayout.java:986)
  at androidx.drawerlayout.widget.DrawerLayout.isDrawerOpen (DrawerLayout.java:1836)
  at com.mikepenz.materialdrawer.Drawer.isDrawerOpen (Drawer.java:153)
  at xxx.yyy.zzz.MainActivity.onBackPressed (MainActivity.kt:292)
  at xxx.yyy.zzz.FragmentNavigatorImpl.navigateBack (FragmentNavigatorImpl.kt:72)
  at xxx.yyy.zzz.MainActivity.navigateBack (MainActivity.kt:344)
  at xxx.yyy.zzz.MainActivity.onBackPressed (MainActivity.kt:310)
  at xxx.yyy.zzz.FragmentNavigatorImpl.navigateBack (FragmentNavigatorImpl.kt:72)
  at xxx.yyy.zzz.MainActivity.navigateBack (MainActivity.kt:344)
  at xxx.yyy.zzz.MainActivity.onBackPressed (MainActivity.kt:310)

However, these stack traces are not reported in Raygun. I can confirm we have set up/initialised the RaygunClient correctly using the following code in our Activity's onCreate() method:

RaygunClient.init(application)
RaygunClient.setVersion(BuildConfig.VERSION_NAME)
RaygunClient.enableCrashReporting()
RaygunPageTags.init(deviceType)
RaygunClient.enableRUM(this)

Is there anything that could be preventing Raygun from reporting these StackOverflow crashes?

Version ussed: 4.0.1

Thank you for your support.

@rs146 Is it only StackOverflowErrors you're missing?

Would you have a reproducible case that triggers this?

rs146 commented

Hi @TheRealAgentK - yes it's only StackOverflow Errors that we are missing. I can confirm we are receiving all other crash logs.

The StackOverflow case in the above example occurs in this scenario/use-case - when a user presses the Back button on the device. (The following code snippet has been shortened for clarity). In an Activity, override the onBackPressed() function with the below code:

override fun onBackPressed() {
     onBackPressed()
}

Although the logic is much more complex in our codebase - however, this is the core issue of the StackOverflow error that we have seen; but not reported in our Raygun logs.

If this appears in Raygun, another option would be to do the following:

class MainActivity {
     val someWorker = SomeWorker()

     override fun onBackPressed() {
            someWorker.doWork(this)
     }
}

class SomeWorker {
      fun doWork(activity: Activity) {
             activity.onBackPressed()
      }
}

The core issue here seems to be that when a StackOverflowError occurs, we're essentially dealing with a VirtualMachineError that almost instantly crashes the virtual machine on the device before our hook into the unhandled exception tracker can even kick in - exaggerated by a lack of stack frames because of the StackOverflowError.

Anecdotally some people had some success in catching this by re-throwing any VirtualMachineError as a more specialized exception, but that avenue will require some further exploration and it's currently unclear if that's a generally applicable solution.

This will be addressed in work for a new release.