From e40aed3a7d362733ef22fb7176634c804917b1af Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Wed, 24 Apr 2024 19:17:00 +0100 Subject: [PATCH] fix(state-accessor): hold the state_lock when checking if a user can invite --- src/service/rooms/state_accessor/mod.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/service/rooms/state_accessor/mod.rs b/src/service/rooms/state_accessor/mod.rs index 9a3580dd..53e3176f 100644 --- a/src/service/rooms/state_accessor/mod.rs +++ b/src/service/rooms/state_accessor/mod.rs @@ -21,6 +21,7 @@ use ruma::{ EventId, JsOption, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId, }; use serde_json::value::to_raw_value; +use tokio::sync::MutexGuard; use tracing::{error, warn}; use crate::{service::pdu::PduBuilder, services, Error, PduEvent, Result}; @@ -309,6 +310,7 @@ impl Service { room_id: &RoomId, sender: &UserId, target_user: &UserId, + state_lock: &MutexGuard<'_, ()>, ) -> Result { let content = to_raw_value(&RoomMemberEventContent::new(MembershipState::Invite)) .expect("Event content always serializes"); @@ -321,21 +323,10 @@ impl Service { redacts: None, }; - let mutex_state = Arc::clone( - services() - .globals - .roomid_mutex_state - .write() - .await - .entry(room_id.to_owned()) - .or_default(), - ); - let state_lock = mutex_state.lock().await; - Ok(services() .rooms .timeline - .create_hash_and_sign_event(new_event, sender, room_id, &state_lock) + .create_hash_and_sign_event(new_event, sender, room_id, state_lock) .is_ok()) }