Async-storage: Failed to open database RKStorage (language)

Created on 2 Aug 2019  路  13Comments  路  Source: react-native-async-storage/async-storage

Current behavior

After changing the device language the app crashs.

Expected behavior

No impact on the app when user changes the device language.

Repro steps

  1. Install a release build using some language, like en_US
  2. Kill the app
  3. Change the device language, for example pt_BR
  4. Open the app
  5. App crashs

Environment

  • Async Storage version: 1.6.1
  • React-Native version: 0.60.4
  • Platform tested: Android
  • Logs/Error that are relevant:
Failed to open database "/data/user/0/com.app/databases/RKStorage".
android.database.sqlite.SQLiteException: Failed to change locale for db "/data/user/0/com.app/databases/RKStorage" to "en_US".
    at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:394)
    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:219)
    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:194)
    at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:493)
    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:200)
    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:192)
    at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:864)
    at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:849)
    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:724)
    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:714)
    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:295)
    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:238)
    at com.facebook.react.modules.storage.ReactDatabaseSupplier.ensureDatabase(ReactDatabaseSupplier.java:88)
    at com.facebook.react.modules.storage.AsyncStorageModule.ensureDatabase(AsyncStorageModule.java:432)
    at com.facebook.react.modules.storage.AsyncStorageModule.access$000(AsyncStorageModule.java:38)
    at com.facebook.react.modules.storage.AsyncStorageModule$1.doInBackgroundGuarded(AsyncStorageModule.java:132)
    at com.facebook.react.modules.storage.AsyncStorageModule$1.doInBackgroundGuarded(AsyncStorageModule.java:129)
    at com.facebook.react.bridge.GuardedAsyncTask.doInBackground(GuardedAsyncTask.java:32)
    at com.facebook.react.bridge.GuardedAsyncTask.doInBackground(GuardedAsyncTask.java:20)
    at android.os.AsyncTask$2.call(AsyncTask.java:333)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at com.facebook.react.modules.storage.AsyncStorageModule$SerialExecutor$1.run(AsyncStorageModule.java:64)
    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)
Caused by: android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5)
    at android.database.sqlite.SQLiteConnection.nativeExecute(Native Method)
    at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:556)
    at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:385)
    ... 24 more   
(1032) statement aborts at 14: [INSERT OR REPLACE INTO catalystLocalStorage VALUES (?, ?);] attempt to write a readonly database
attempt to write a readonly database (code 1032)
android.database.sqlite.SQLiteReadOnlyDatabaseException: attempt to write a readonly database (code 1032)
    at android.database.sqlite.SQLiteConnection.nativeExecute(Native Method)
    at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:556)
    at android.database.sqlite.SQLiteSession.execute(SQLiteSession.java:619)
    at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:44)
    at com.reactnativecommunity.asyncstorage.AsyncStorageModule$2.doInBackgroundGuarded(AsyncStorageModule.java:235)
    at com.reactnativecommunity.asyncstorage.AsyncStorageModule$2.doInBackgroundGuarded(AsyncStorageModule.java:205)
    at com.facebook.react.bridge.GuardedAsyncTask.doInBackground(GuardedAsyncTask.java:32)
    at com.facebook.react.bridge.GuardedAsyncTask.doInBackground(GuardedAsyncTask.java:20)
    at android.os.AsyncTask$2.call(AsyncTask.java:333)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at com.reactnativecommunity.asyncstorage.AsyncStorageModule$SerialExecutor$1.run(AsyncStorageModule.java:62)
    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)
--------- beginning of crash
[ 31506:31506 E/AndroidRuntime ]
FATAL EXCEPTION: main
Process: com.app, PID: 31506
android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground()
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6626)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

Most helpful comment

Hi folks

I have seen similar errors popping up in our Sentry report.

android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5 SQLITE_BUSY[5]): , while compiling: PRAGMA cache_size
    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1229)
    at android.database.sqlite.SQLiteConnection.executeForLong(SQLiteConnection.java:797)
    at android.database.sqlite.SQLiteConnection.setCacheSizeFromConfiguration(SQLiteConnection.java:423)
    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:302)
    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:215)
    at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:705)
    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:272)
    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:239)
    at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:1292)
    at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:1247)
    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:903)
    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:893)
    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:365)
    at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:322)
    at com.hoxfon.react.RNTwilioVoice.TwilioVoiceModule.accept(TwilioVoiceModule.java:549)
    at com.hoxfon.react.RNTwilioVoice.TwilioVoiceModule$VoiceBroadcastReceiver.onReceive(TwilioVoiceModule.java:449)
    at android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:313)
    at android.support.v4.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:121)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7073)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)

Do you know what can we do? Upgrade/downgrade lib version?

All 13 comments

@Bruno-Furtado Thanks for filling this one up. I'll have a look

I also got attempt to write a readonly database (code 1032 SQLITE_READONLY_DBMOVED[1032]) error.

@Bardiamist Could you provide some repro steps to get this error? I've tried to follow from author, but with no luck.

@Krizzu Unfortunately no, I got this from Sentry report.
Android 9 SM-G965F
React native version: 0.60.5
Async storage version: 1.6.1

This error is reported from multiple users on Sentry for my app as well. Error is database is locked (code 5)

Hi folks

I have seen similar errors popping up in our Sentry report.

android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5 SQLITE_BUSY[5]): , while compiling: PRAGMA cache_size
    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1229)
    at android.database.sqlite.SQLiteConnection.executeForLong(SQLiteConnection.java:797)
    at android.database.sqlite.SQLiteConnection.setCacheSizeFromConfiguration(SQLiteConnection.java:423)
    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:302)
    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:215)
    at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:705)
    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:272)
    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:239)
    at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:1292)
    at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:1247)
    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:903)
    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:893)
    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:365)
    at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:322)
    at com.hoxfon.react.RNTwilioVoice.TwilioVoiceModule.accept(TwilioVoiceModule.java:549)
    at com.hoxfon.react.RNTwilioVoice.TwilioVoiceModule$VoiceBroadcastReceiver.onReceive(TwilioVoiceModule.java:449)
    at android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:313)
    at android.support.v4.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:121)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7073)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)

Do you know what can we do? Upgrade/downgrade lib version?

I ran into the same thing and it turned out that I had hit the max default size for AsyncStorage on Android which is only 6MB. I followed the info at https://github.com/bigsassy/react-native/commit/7f766b8bfdcef86f17b28bf9482c4399084bd729 and that resolved my issue.

@bscheideldyrt You might be interested in docs about changing size of db for android

We're still seeing the same error SQLITE_READONLY_DBMOVED even with increasing the storage size.

@eabait - you got a different error code (5) to the one in the original report (1032), so you should file a separate issue.

@bscheideldyrt - which error code did you mean when you said "the same thing"?

https://www.sqlite.org/rescode.html is the sqlite documentation for these error codes.

https://github.com/react-native-community/async-storage/issues/206 mentions a crash for error code 1032 (and error code 1 too).

Hey :wave:

Please checkout #423, where I try to address the issue.

Addressed by #423

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Alaa-Ben picture Alaa-Ben  路  20Comments

santhanakrishnanstark picture santhanakrishnanstark  路  67Comments

michaelsinatra picture michaelsinatra  路  24Comments

cohawk picture cohawk  路  28Comments

sumanthyedoti picture sumanthyedoti  路  25Comments