Skip to content

Commit 03061ca

Browse files
adalpariclaude
andauthored
Enable WAL on the Reader database to prevent onStart ANRs (#23116)
Without WAL, Android caps the reader DB connection pool at one connection, serializing all reads/writes across threads. A main-thread tag read in ReaderPostListFragment.onStart could then block behind a background write (purge/reset/addOrUpdatePosts) long enough to trigger an ANR. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent a2047ac commit 03061ca

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

WordPress/src/main/java/org/wordpress/android/datasets/ReaderDatabase.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,17 @@ public ReaderDatabase(Context context) {
187187
super(context, DB_NAME, null, DB_VERSION);
188188
}
189189

190+
@Override
191+
public void onConfigure(SQLiteDatabase db) {
192+
super.onConfigure(db);
193+
// Enable Write-Ahead Logging so reads and a single writer can run concurrently. Without WAL,
194+
// Android caps the connection pool at a single connection for the whole reader DB, which
195+
// serializes every read/write across all threads. That serialization causes ANRs when a
196+
// main-thread read (e.g. reloading Reader tags in onStart) blocks behind a background write
197+
// such as purge()/reset()/addOrUpdatePosts(). See ReaderTagTable.getTagFromEndpoint ANR.
198+
db.enableWriteAheadLogging();
199+
}
200+
190201
@Override
191202
public void onCreate(SQLiteDatabase db) {
192203
createAllTables(db);

0 commit comments

Comments
 (0)