Mysterious Signal 11 crash when accessing Room database - android

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
Only creating the room entity without inserting it in to the DB still produces the crash
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)
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.
replacing rxandroid for kotlin coroutines. The crash still happens after this
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.
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...
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
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.

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

Having to post as an answer due to the character limit
Going to tack onto this as i was experiencing the same thing across two different EMU's - 28 and 30. Two weeks of debugging i came across this. I felt like my app was simple.
Core composed Dagger2 RxJava2, Room, Retrofit, Material etc.
Main Activity A contained 5 set fragments and 3 were liveData. - fine.
Moved to Class B, fine, Getting a list of Objects from DB. - fine
Moved to Class C, crashing from instant - 7 seconds. This was a similar setup, Class C, contained Fragments that observed different LiveData.
No errors, nothing on debug - just the debugger disconnecting, nothing in logcat except like the above. Nothing in tombstone. Just channel closing + I/Zygote: Process xxxx exited due to signal (11)
The app would always fireup the previous activity or the same activity with no database data.
Fired up leakcanry, nothing there, Fired up Google vitals nothing there, fired up Firebase crashlytics and still nothing there. Even fired up Airbrake, still nothing.
Switched to Class D, that was highly similar to class C but skipped Class B, - still crashing.
Switched to Class E, no live data but saved to DB directly, crashing there.
I have performed the usual invalid cache and restart, wipe data on the EMU's...alot more debugging attempts... Fast forward two weeks, and i came upon this and it saved me having to rip Room out.
Solution:
I had to create all new EMU's. Now the exact same code is working from Android 23 to 30.

Related

Why android room throwing CursorWindowAllocationException? [duplicate]

This question already has an answer here:
android.database.CursorWindowAllocationException when moving a Cursor
(1 answer)
Closed 9 months ago.
I use the room orm for saving data in my app. My app is running on android 5.1.1 and also I use androidx in the project. But after a while I got the below exception:
Fatal Exception: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed.
at android.database.CursorWindow.(CursorWindow.java:108)
at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:226)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:148)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:142)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:219)
at android.database.AbstractCursor.moveToNext(AbstractCursor.java:268)
at android.arch.persistence.room.InvalidationTracker$1.checkUpdatedTable(InvalidationTracker.java:358)
at android.arch.persistence.room.InvalidationTracker$1.run(InvalidationTracker.java:329)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
But indeed Room manages Cursor automatically and there isn't any Cursor class in the whole project and furthermore, when this error happens there isn't any database-related transaction.
Finally, I found the answer. Be careful when you use WorkManager. It creates a database and updates work statuses and when this database grows it causes a crash. Here is detailed information.
WorkManager database: A local database that tracks all of the information and statuses of all of your work. This includes things like the current state of the work, the inputs and outputs to and from the work ,and any constraints on the work. This database is what enables WorkManager to guarantee your work will finish — if your user’s device restarts and work gets interrupted, all of the details of the work can be pulled from the database and the work can be restarted when the device boots up again.
Use pruneWork() in WorkManager when necessary

Android Lollipop 5.0.1 SQLiteLog POSIX Error 11 SQLite Error: 3850

I am having an issue while upgrading an app to support Android Lollipop.
The app implements a SyncAdapter that writes on a db through a content provider.
At the same time it can happen that the user is browsing the front-end of the app where loaders read the same data from the database.
Loaders also listen to data changes.
Now, if I run the program on a pre-Lollipop device everything works without any error output.
On Lollipop instead I receive the following logcat message:
11:20:59.344 22341-22376/com.example.com E/SQLiteLog﹕ (10) POSIX Error : 11 SQLite Error : 3850
11:20:59.364 22341-22376/com.example.com E/SQLiteLog﹕ (10) POSIX Error : 11 SQLite Error : 3850
11:20:59.364 22341-22376/com.example.com E/SQLiteLog﹕ (10) POSIX Error : 11 SQLite Error : 3850
11:20:59.364 22341-22376/com.example.com E/SQLiteLog﹕ (10) POSIX Error : 11 SQLite Error : 3850
Now, from SQLite docs:
(3850) SQLITE_IOERR_LOCK
The SQLITE_IOERR_LOCK error code is an extended error code for
SQLITE_IOERR indicating an I/O error in the advisory file locking
logic. Usually an SQLITE_IOERR_LOCK error indicates a problem
obtaining a PENDING lock. However it can also indicate miscellaneous
locking errors on some of the specialized VFSes used on Macs.
Everything seems to work properly on a high level (that is both reads
and writes are performed)
and:
A PENDING lock means that the process holding the lock wants to write
to the database as soon as possible and is just waiting on all current
SHARED locks to clear so that it can get an EXCLUSIVE lock. No new
SHARED locks are permitted against the database if a PENDING lock is
active, though existing SHARED locks are allowed to continue.
I know that the SQLite version has been updated by few major releases in Lollipop, so I am prone to think that the error is due to some new behaviour of SQLite that I cannot isolate.
However, everything seems to work fine from a higher level point of view (App doesn't crash, both reads and writes are performed, framerate doesn't drop - at least to human eyes) but I wouldn't want to ignore the issue to release the app until I am sure it won't cause data corruption or troubles.
Perhaps I am missing on some important changes to lollipop regarding locks and multiprocess database access, but I feel it's an issue that lies on a lower level with respect to the Art/Dalvik domain and so has to be fixed in an NDK context.
Is there a way to fix this possibly without distributing an app specific version of SQLite? Is there any manifest/SQLite option to avoid the error?
Thanks in advance
Writer locks the database for both reading and writing.
That means it has to wait for all readers to finish and release locks in order to obtain lock.
After the writer requested a lock, new reader locks must wait for writer to first obtain lock and then release it.
This could be a solution for you: WAL mode
Activating And Configuring WAL Mode:
An SQLite database connection defaults to journal_mode=DELETE. To convert to WAL mode, use the following pragma:
PRAGMA journal_mode=WAL;
WAL will not block readers while writing, which means also that writer does not need to wait for current read locks to be released.
Minimum SQLite version required for WAL is 3.7.0 (2010-07-21).
Lollipop 5.0 uses SQLite 3.8.4.3 so WAL should be available for you.
But WAL does not exist in Android version less than 3.0 although there are some exceptions from this. Take a look at Version of SQLite used in Android?. If you don't need your app to work below Android 3.0 you can use WAL.

Android Multithreading - WaitForGcToComplete after sending app to background

I'm using Android L for some heavily multi-threaded operations, using multiple ThreadPoolExecutors to run queues of AsyncTasks.
When my app goes to the background, I start seeing numerous logs for...
I/art: WaitForGcToComplete blocked for ##.#####ms for cause XXXXX
...with an occasional...
I/art: No such thread id for suspend: ###.
It seems clear that something is going on that's making GC take longer than expected. The log gets generated by art/runtime/gc/heap.cc deep in the AOSP. The secondary log message indicates it's probably related to my thread pools. What isn't clear is why this is only happening (i.e. getting logged) when the app is sent to the background.
I haven't seen any crashes yet due to this, but I have a lot more testing to go through. Has anyone out there run into issues coinciding with these logs?

How to solve showStatusIcon on inactive InputConnection [duplicate]

This question already has an answer here:
Android input connection error
(1 answer)
Closed 7 years ago.
When I close my app I get this message on LogCat
showStatusIcon on inactive InputConnection
I read somewhere, but I'm not sure, that it means that I didn't release something, something related to the memory usage.
How can I solve this problem?
Such problems occur when the input connection in the previous page(or class) has not been closed. Check whether you've closed the input connection in the previous class (by giving connection.close()).
from
Android input connection error
from the documentation
The InputConnection interface is the communication channel from an InputMethod back to the application that is receiving its input. It is used to perform such things as reading text around the cursor, committing text to the text box, and sending raw key events to the application.
In addition, further reading shows
getExtractedText(): This method may fail either if the input connection has become invalid (such as its process crashing) or the client is taking too long to respond with the text (it is given a couple seconds to return). In either case, a null is returned.
It appears to also monitor changes to such text, and alert changes.
To hunt the issue down you'll have to explore any queries you are making, perhaps around listViews or lists in a layout.
If you don't have any views, for example it's happening randomly in the background, then i would suggest that its not a UI element issue, so ignore textfields and such. It could be a background service that's storing information in a cursor or requesting a cursor.
Also, does the issue arise from your app? or perhaps someone else's that you've installed recently. List the full logCat trace. Someone might recognise the issue.
I would hazard a guess that if you haven't written something specific around this that its someone elses log message, or perhaps that of a library your using?

App dies with "Sending signal." but no exception or other info

I'm working on an app that is recording data via Bluetooth, but it intermittently crashes after hours of collecting data (making it hard to track down the bug).
The logcat output isn't very helpful:
http://i.imgur.com/EalnX.png
There are no exceptions thrown and no clues for what caused the process to be terminated.
How can I figure out what went wrong? Is there an exception being thrown that isn't being shown by logcat? How can I track this bug down?
Signal 9 is SIGKILL, which will terminate a process immediately (no handlers inside the process will run). From the log line, the process is killing itself, so its not an external agent that is issuing the SIGKILL.
My guess (and its really a guess) is that the memory management code running inside your process (as part of the infrastructure, not code that you wrote) is deciding that you've exhausted some resource and the only recourse is to die. I would expect there to be more messages before this point is reached in the log, so it may be worth browsing the log history to see if there are useful warnings from the process before this point.
The line immediately before this is a GC log, which implies that some sort of memory resource is running low. But it looks like the heaps are not full, so failing allocations seems unlikely. You can still get allocation failures if the object being allocated was too large to fit on the heap, or fragmentation prevented it from being allocated. I'd expect to see more relevant log messages in this case, though.
I think capturing more of the log (perhaps filtering it by your app's PID if necessary) will help you make progress.
In my case there was no warnings or any clues in the log.
Eventually I found that my problem was that one of the activities I was going into (lets say Activity X) was registering to a broadcast receiver but never unregistered from it.
Therefor by closing the activity (Activity X) and coming back to it caused registering Again to the same broadcast receiver - which caused the mess!
Simply adding unregisterReceiver(mybroadcast); (in Activity X) solved it.
(I added mine to onDestroy. make sure you unregister in the right location).
And if you are super desperate I recommend seeing this slide share which explains Android crash debugging your errors.
this problem happens when using RXjava and not implement the onError callback method

Categories

Resources