diff --git a/crates/matrix-sdk-sqlite/src/event_cache_store.rs b/crates/matrix-sdk-sqlite/src/event_cache_store.rs index 88cdd18ec..854c7b206 100644 --- a/crates/matrix-sdk-sqlite/src/event_cache_store.rs +++ b/crates/matrix-sdk-sqlite/src/event_cache_store.rs @@ -178,6 +178,15 @@ impl SqliteEventCacheStore { async fn acquire(&self) -> Result { let connection = self.pool.get().await?; + // Specify a busy timeout so that operations are automatically retried, in case + // the database was marked as locked, which can happen under very + // peculiar circumstances in WAL mode. + // + // The timeout value is in milliseconds. + // + // See also https://www.sqlite.org/wal.html#sometimes_queries_return_sqlite_busy_in_wal_mode. + connection.execute_batch("PRAGMA busy_timeout = 2000;").await?; + // Per https://www.sqlite.org/foreignkeys.html#fk_enable, foreign key // support must be enabled on a per-connection basis. Execute it every // time we try to get a connection, since we can't guarantee a previous