mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-16 12:43:01 -04:00
feat: don't recreate the cross-process lock if it already existed
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user