@@ -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