Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLiteDiskIOException: disk I/O error (code 3850)

I get above mentioned error on some devices (very rarely, 2 times until now only):

android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 3850)
    at android.database.sqlite.SQLiteConnection.nativeExecuteForString(Native Method)
    at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:679)
    at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:361)
    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:236)
    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:200)
    at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
    at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:806)
    at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
    at ***.a(***.java:115)

The line 115 in my code is following:

// here the exception occurs
SQLiteDatabase db = SQLiteDatabase.openDatabase(pathApp, null, SQLiteDatabase.OPEN_READONLY); 
// ...
db.close();

Story

What I do is following:

  • app has root rights
  • it copies the database from another app into it's own directory
  • it tries to open this database and read some data
  • it close the file again

That's all. This is working on thousands of devices. My app for sure only accesses the database at on place, I'm completely sure about that

Question

Does anyone know what could cause this problem?

Maybe interesting facts

  • the 2 devices are a OnePlus2
  • one guy told me that the problem occurred after updating to Oxygen 2.1
like image 434
prom85 Avatar asked Oct 31 '22 18:10

prom85


2 Answers

I came across a similar problem recently where my app runs fine on all Android devices except the OnePlus Two running OxygenOS 2.1.

After looking into the issue, it appears this specific combination is very sensitive and crashes on a database lock of some sort. In my case, my app was copying a new database to the device on the first run then checking the database version to see if it requires an update. On the check it crashed on these devices. I realized in my code I am opening a separate instance to the database instead of using the currently opened database when checking the version. After changing the code to avoid opening a separate instance of the database, the app stopped crashing on the OnePlus.

My advice is to Not open multiple instances of the database in your app or try closing the database first before opening it again (perhaps your copy method didn't close the database or is using another instance of the same database).

like image 193
hbustan Avatar answered Nov 18 '22 17:11

hbustan


Just encountered this in development. It triggered when the phone ran out of batteries and shut down. Presumably, you just have to be grabbing the database lock when that happens.

like image 20
dhakim Avatar answered Nov 18 '22 17:11

dhakim