Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bindings/matrix-sdk-base/changelog.d/6555.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
`Client::sync_once` acquires the state store lock when processing a sync and
response and holds it until processing has completed. This mimics the behavior
of `SlidingSync::sync_once`.
16 changes: 9 additions & 7 deletions crates/matrix-sdk-base/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,10 @@ impl BaseClient {

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

// Acquire the state store lock and hold on to it while processing
// the sync response below.
let state_store_guard = self.state_store_lock().lock().await;

let user_id = self
.session_meta()
.expect("Sync shouldn't run without an authenticated user")
Expand Down Expand Up @@ -766,7 +770,7 @@ impl BaseClient {
processors::changes::save_and_apply(
context,
&self.state_store,
&self.state_store_lock().lock().await,
&state_store_guard,
&self.ignore_user_list_changes,
Some(response.next_batch.clone()),
)
Expand All @@ -784,12 +788,7 @@ impl BaseClient {
.await;

// Save the new display name updates if any.
processors::changes::save_only(
context,
&self.state_store,
&self.state_store_lock().lock().await,
)
.await?;
processors::changes::save_only(context, &self.state_store, &state_store_guard).await?;

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

// Release the state store lock
drop(state_store_guard);

if enabled!(Level::INFO) {
info!("Processed a sync response in {:?}", now.map(|now| now.elapsed()));
}
Expand Down
Loading