Skip to content

Commit 1a8c8be

Browse files
authored
Merge pull request #6300 from nymtech/simon/db_lock_cherrypick
[cherrypick] fix credential db locking
2 parents 9ac7f12 + d03262f commit 1a8c8be

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

common/credential-storage/src/backends/sqlite.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ impl SqliteEcashTicketbookManager {
3939
Ok(())
4040
}
4141

42-
pub(crate) async fn begin_storage_tx(&self) -> Result<Transaction<'_, Sqlite>, sqlx::Error> {
43-
self.connection_pool.begin().await
42+
/// Starts a write (IMMEDIATE) transaction, to prevent issue when upgrading from a read one to a write one
43+
pub(crate) async fn begin_storage_write_tx(
44+
&self,
45+
) -> Result<Transaction<'_, Sqlite>, sqlx::Error> {
46+
self.connection_pool.begin_with("BEGIN IMMEDIATE").await
4447
}
4548

4649
pub(crate) async fn insert_pending_ticketbook(

common/credential-storage/src/persistent_storage/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl Storage for PersistentStorage {
243243
tickets: u32,
244244
) -> Result<Option<RetrievedTicketbook>, Self::StorageError> {
245245
let deadline = ecash_today().ecash_date();
246-
let mut tx = self.storage_manager.begin_storage_tx().await?;
246+
let mut tx = self.storage_manager.begin_storage_write_tx().await?;
247247

248248
// we don't want ticketbooks with expiration in the past
249249
let Some(raw) =

0 commit comments

Comments
 (0)