Skip to content

Commit fb1d04c

Browse files
mgoldenbergpoljar
authored andcommitted
refactor(base): hold state store lock while processing sync response
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
1 parent 8675cb2 commit fb1d04c

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
`Client::sync_once` acquires the state store lock when processing a sync and
2+
response and holds it until processing has completed. This mimics the behavior
3+
of `SlidingSync::sync_once`.

crates/matrix-sdk-base/src/client.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,10 @@ impl BaseClient {
594594

595595
let now = if enabled!(Level::INFO) { Some(Instant::now()) } else { None };
596596

597+
// Acquire the state store lock and hold on to it while processing
598+
// the sync response below.
599+
let state_store_guard = self.state_store_lock().lock().await;
600+
597601
let user_id = self
598602
.session_meta()
599603
.expect("Sync shouldn't run without an authenticated user")
@@ -766,7 +770,7 @@ impl BaseClient {
766770
processors::changes::save_and_apply(
767771
context,
768772
&self.state_store,
769-
&self.state_store_lock().lock().await,
773+
&state_store_guard,
770774
&self.ignore_user_list_changes,
771775
Some(response.next_batch.clone()),
772776
)
@@ -784,12 +788,7 @@ impl BaseClient {
784788
.await;
785789

786790
// Save the new display name updates if any.
787-
processors::changes::save_only(
788-
context,
789-
&self.state_store,
790-
&self.state_store_lock().lock().await,
791-
)
792-
.await?;
791+
processors::changes::save_only(context, &self.state_store, &state_store_guard).await?;
793792

794793
for (room_id, member_ids) in updated_members_in_room {
795794
if let Some(room) = self.get_room(&room_id) {
@@ -798,6 +797,9 @@ impl BaseClient {
798797
}
799798
}
800799

800+
// Release the state store lock
801+
drop(state_store_guard);
802+
801803
if enabled!(Level::INFO) {
802804
info!("Processed a sync response in {:?}", now.map(|now| now.elapsed()));
803805
}

0 commit comments

Comments
 (0)