Skip to content

Commit 7fb57ea

Browse files
committed
chore: Move the cross-process lock enabling into a separate method
1 parent 4d9e418 commit 7fb57ea

File tree

1 file changed

+19
-18
lines changed
  • crates/matrix-sdk/src/oidc

1 file changed

+19
-18
lines changed

crates/matrix-sdk/src/oidc/mod.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -300,17 +300,17 @@ impl Oidc {
300300
/// olm machine has been initialized.
301301
///
302302
/// Must be called after `set_session_meta`.
303-
async fn deferred_enable_cross_process_refresh_lock(&self) -> Result<()> {
303+
async fn deferred_enable_cross_process_refresh_lock(&self) {
304304
let deferred_init_lock = self.ctx().deferred_cross_process_lock_init.lock().await;
305305

306306
// Don't `take()` the value, so that subsequent calls to
307307
// `enable_cross_process_refresh_lock` will keep on failing if we've enabled the
308308
// lock at least once.
309309
let Some(lock_value) = deferred_init_lock.as_ref() else {
310-
return Ok(());
310+
return;
311311
};
312312

313-
// FIXME We shouldn't be using the crypto store for that! see also https://github.com/matrix-org/matrix-rust-sdk/issues/2472
313+
// FIXME: We shouldn't be using the crypto store for that! see also https://github.com/matrix-org/matrix-rust-sdk/issues/2472
314314
let olm_machine_lock = self.client.olm_machine().await;
315315
let olm_machine =
316316
olm_machine_lock.as_ref().expect("there has to be an olm machine, hopefully?");
@@ -323,8 +323,6 @@ impl Oidc {
323323
// This method is guarded with the `deferred_cross_process_lock_init` lock held,
324324
// so this `set` can't be an error.
325325
let _ = self.ctx().cross_process_token_refresh_manager.set(manager);
326-
327-
Ok(())
328326
}
329327

330328
/// The OpenID Connect authentication data.
@@ -708,7 +706,7 @@ impl Oidc {
708706
};
709707

710708
self.client.set_session_meta(meta).await?;
711-
self.deferred_enable_cross_process_refresh_lock().await?;
709+
self.deferred_enable_cross_process_refresh_lock().await;
712710

713711
self.client
714712
.inner
@@ -913,14 +911,23 @@ impl Oidc {
913911
// At this point the Olm machine has been set up.
914912

915913
// Enable the cross-process lock for refreshes, if needs be.
916-
self.deferred_enable_cross_process_refresh_lock().await?;
914+
self.enable_cross_process_lock().await.map_err(OidcError::from)?;
915+
916+
#[cfg(feature = "e2e-encryption")]
917+
self.client.encryption().run_initialization_tasks(None).await;
918+
919+
Ok(())
920+
}
921+
922+
pub(crate) async fn enable_cross_process_lock(
923+
&self,
924+
) -> Result<(), CrossProcessRefreshLockError> {
925+
// Enable the cross-process lock for refreshes, if needs be.
926+
self.deferred_enable_cross_process_refresh_lock().await;
917927

918928
if let Some(cross_process_manager) = self.ctx().cross_process_token_refresh_manager.get() {
919929
if let Some(tokens) = self.session_tokens() {
920-
let mut cross_process_guard = cross_process_manager
921-
.spin_lock()
922-
.await
923-
.map_err(|err| crate::Error::Oidc(err.into()))?;
930+
let mut cross_process_guard = cross_process_manager.spin_lock().await?;
924931

925932
if cross_process_guard.hash_mismatch {
926933
// At this point, we're finishing a login while another process had written
@@ -932,16 +939,10 @@ impl Oidc {
932939
);
933940
}
934941

935-
cross_process_guard
936-
.save_in_memory_and_db(&tokens)
937-
.await
938-
.map_err(|err| crate::Error::Oidc(err.into()))?;
942+
cross_process_guard.save_in_memory_and_db(&tokens).await?;
939943
}
940944
}
941945

942-
#[cfg(feature = "e2e-encryption")]
943-
self.client.encryption().run_initialization_tasks(None).await;
944-
945946
Ok(())
946947
}
947948

0 commit comments

Comments
 (0)