firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.26k stars 572 forks source link

database is locked in "PRAGMA journal_mode" #2640

Closed bolds07 closed 3 years ago

bolds07 commented 3 years ago

[READ] Step 1: YES

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

An stacktrace error message is displayed when trying to run a query with very huge result

The user running the query has access to the data the field used to sort is indexed on rules the mentioned brunch have about hundred thousand nodes each object having about 15 fields [counting nested fields]

Steps to reproduce:

E/SQLiteLog: (5) database is locked in "PRAGMA journal_mode"
E/SQLiteDatabase: Failed to open database '/data/user/0/com.tomatedigital.instagramgiveawaywinner/databases/google_app_measurement_local.db'.
    android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5 SQLITE_BUSY): , while compiling: PRAGMA journal_mode
        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1045)
        at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:788)
        at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:405)
        at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:345)
        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:258)
        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:205)
        at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:505)
        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:206)
        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:198)
        at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:918)
        at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:898)
        at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:762)
        at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:751)
        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:373)
        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:316)
        at ht.getWritableDatabase(:com.google.android.gms.policy_measurement_dynamite@218057@218057.364935860.364935860:1)
        at hu.p(:com.google.android.gms.policy_measurement_dynamite@218057@218057.364935860.364935860:0)
        at hu.f(:com.google.android.gms.policy_measurement_dynamite@218057@218057.364935860.364935860:3)
        at jv.T(:com.google.android.gms.policy_measurement_dynamite@218057@218057.364935860.364935860:85)
        at jc.run(:com.google.android.gms.policy_measurement_dynamite@218057@218057.364935860.364935860:0)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at ik.run(:com.google.android.gms.policy_measurement_dynamite@218057@218057.364935860.364935860:5)

Relevant Code:

App.getDatabaseInstance().getReference("store/orders/historic/").orderByChild("creationTs").limitToFirst(1000).endAt(System.currentTimeMillis() - (45L * ONE_DAY_MILLIS)).addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                    if (dataSnapshot.hasChildren()) {

                        for (DataSnapshot historicDs : dataSnapshot.getChildren()) {
                        //do stuff

                        }

                            App.getDatabaseInstance().getReference("store/orders/historic/").orderByChild("creationTs").limitToFirst(1000).endAt(System.currentTimeMillis() - (45L * ONE_DAY_MILLIS)).addListenerForSingleValueEvent(this);
                        }  
                    } else
                        System.out.println("FINISHED!!! ");
                }

                @Override
                public void onCancelled(@NonNull DatabaseError databaseError) {

                }
            });
aguatno commented 3 years ago

Hi @bolds07 thanks for reporting. It looks like the error is coming from the Android SQLiteDatabase class. I can't reproduce this locally. It would be great if you can provide a minimal, complete, reproducible code demonstrating the issue. Along with the code, also provide me with detailed steps on how to reproduce it. I’d like to see how this error is produced so I can immediately raise it to the team for investigation.

Aside from the repro, you can also try to check the quickstart for Android and see if you’ll be able to reproduce this issue using that sample. If so, please let me know and provide the necessary details so I can investigate on my end.

google-oss-bot commented 3 years ago

Hey @bolds07. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 3 years ago

Since there haven't been any recent updates here, I am going to close this issue.

@bolds07 if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.