Search code examples
androidsegmentation-faultandroid-roomkoin

Mysterious Signal 11 crash when accessing Room database


About

I have an android application, which has 2 activities. Activity A spawns Activity B, and Activity B accesses Room Database in another module. I'm using Koin for all dependency injections, and rxandroid (Schedulers.io() for observing and UI thread for observing) to observe the database transaction

The Issue

When I access the database, the action completes successfully, an entry is added in the database, and then 1-2 seconds later the activity crashes and the app returns to Activity A with no stack trace or any error message in the application logcat.

Im testing the app in AVD Pixel 2 API 28

If I remove all filters from logcat, I can find this error:

2021-01-14 22:31:01.836 9799-9799/com.example.myapp I/System.out: Saving Course
2021-01-14 22:31:01.928 9799-9799/com.example.myapp I/System.out: Added course to DB: 11
2021-01-14 22:31:02.822 9799-9835/com.example.myapp I/om.example.myap: Explicit concurrent copying GC freed 94987(4MB) AllocSpace objects, 0(0B) LOS objects, 49% free, 3MB/6MB, paused 329us total 10.624ms
2021-01-14 22:31:03.439 1935-2006/? W/InputDispatcher: channel '7a68875 com.example.myapp/com.example.myapp.activities.CourseCreatorActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
2021-01-14 22:31:03.439 1935-2006/? E/InputDispatcher: channel '7a68875 com.example.myapp/com.example.myapp.activities.CourseCreatorActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
2021-01-14 22:31:03.441 1935-2006/? W/InputDispatcher: channel '1c99176 com.example.myapp/com.example.myapp.activities.MainActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
2021-01-14 22:31:03.441 1935-2006/? E/InputDispatcher: channel '1c99176 com.example.myapp/com.example.myapp.activities.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
2021-01-14 22:31:03.443 1773-1773/? I/Zygote: Process 9799 exited due to signal (11)

signal 11 is apparently segmentation fault..

What I've tried

  1. Only creating the room entity without inserting it in to the DB still produces the crash
  2. removing Activity A and starting the app on Activity B (which accesses the DB) seems to not produce error (ive tried a few dozen times)
  3. stepping through the save function using the debugger. I can break the main thread or the IO thread, and in both cases the app will crash despite the thread being in break state.
  4. replacing rxandroid for kotlin coroutines. The crash still happens after this
  5. I've tried debugging the app on my phone (pixel 3a) and have so far been unable to reproduce the crash. Will keep trying though.
  6. I tried this on a Pixel 3a AVD at API 30, and couldnt replicate the crash. Then I tried on a Pixel 3a AVD at API 28, and the crash was there. So currently it seems to only happen in API 28...
  7. Tested with API 27 and API 29, both worked fine. Deleted the API 28 SDK and redownloaded it, deleted all related AVDs and recreated them, still getting the signal 11 crash like 2nd try on a fresh install of API 28.. So it seems that the segmentation fault only occurs on Android Pie
  8. I started creating a simplified version of the same overall architecture and logic im using here in an effort to pinpoint where the error originates from exactly. Im not very keen on starting over on the simplified project as without knowing what is causing this error, I would most likely just run in to it again eventually.

Note: Sometimes I will make a change and it will "fix" the issue, only for it to reappear after a while and that makes this really hard to debug with conventional methods

Conclusion

What I really need is some way to debug this. I have no idea what is causing it, and really no idea how to go forward in debugging it.


Solution

  • I changed to a different android API level and the problem has not resurfaced since