sqlite-android icon indicating copy to clipboard operation
sqlite-android copied to clipboard

The primary connection is sometimes used for reads

Open nwagu opened this issue 1 year ago • 0 comments

I ran into a situation where writes are blocked because a long read was being done in the primary connection. Looking at the code, I saw that when the 9 read connections are all in use, the primary connection will be used for the next read if it's available.

// Try to acquire a connection.
SQLiteConnection connection = null;
if (!wantPrimaryConnection) {
    connection = tryAcquireNonPrimaryConnectionLocked(
        sql, connectionFlags); // might throw
}
if (connection == null) {
    connection = tryAcquirePrimaryConnectionLocked(connectionFlags); // might throw
}
if (connection != null) {
    return connection;
}

This might cause an expensive query to block writes to the db. Is this the expected behavior?

nwagu avatar Feb 12 '25 21:02 nwagu