From 672bb9f460465a12c3a362ce5723176d4aaa36ef Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 3 Jun 2025 15:52:22 +0200 Subject: [PATCH] feat: add the busy timeout pragma to the event cache store `acquire()` method too It will tell us if this is sufficient to avoid locking the event cache store database, now that we have some proof that this is happening in the wild. --- crates/matrix-sdk-sqlite/src/event_cache_store.rs | 9 +++++++++ 1 file changed, 9 insertions(+) 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