feat: don't recreate the cross-process lock if it already existed

This commit is contained in:
Benjamin Bouvier
2023-07-03 16:52:34 +02:00
parent 0ef819bca7
commit 4e065ccee9
2 changed files with 15 additions and 0 deletions

View File

@@ -297,6 +297,12 @@ impl CryptoStoreLock {
sleep(Duration::from_millis(wait.into())).await;
}
}
/// Returns the value in the database that represents the holder's
/// identifier.
pub fn lock_holder(&self) -> &str {
&self.lock_holder
}
}
/// Error related to the locking API of the crypto store.

View File

@@ -858,6 +858,15 @@ impl Encryption {
///
/// The provided `lock_value` must be a unique identifier for this process.
pub async fn enable_cross_process_store_lock(&self, lock_value: String) -> Result<(), Error> {
// If the lock has already been created, don't recreate it from scratch.
if let Some(prev_lock) = self.client.inner.cross_process_crypto_store_lock.get() {
let prev_holder = prev_lock.lock_holder();
if prev_holder == lock_value {
return Ok(());
}
warn!("recreating cross-process store lock with a different holder value: prev was {prev_holder}, new is {lock_value}");
}
let olm_machine = self.client.base_client().olm_machine().await;
let olm_machine = olm_machine.as_ref().ok_or(Error::AuthenticationRequired)?;