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.
This commit is contained in:
Benjamin Bouvier
2025-06-03 15:52:22 +02:00
parent 9a75007535
commit 672bb9f460

View File

@@ -178,6 +178,15 @@ impl SqliteEventCacheStore {
async fn acquire(&self) -> Result<SqliteAsyncConn> {
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