refactor(service): Use SyncRwLock and SyncMutex for in-memory services

Convert in-memory data structures in appservice, rooms::typing, and sync
wakers to use SyncRwLock and SyncMutex. Drop appservice locks before
making outbound network requests in room alias queries and federation
invites.
This commit is contained in:
Jade Ellis committed 2026-10-28 21:48:22 +00:00
1 parent 5297e01357
commit 24b1e2ebe8
20 files changed
+126 -160

No files matched your search

+27 -23
View File
@@ -209,31 +209,35 @@ async fn create_invite(
services.sync.wake(&recipient_user).await;
for appservice in services.appservice.read().await.values() {
if appservice.is_user_match(&recipient_user) {
let transaction_id = general_purpose::URL_SAFE_NO_PAD
.encode(sha256::hash(pdu.event_id.as_bytes()))
.into();
let matching_appservices: Vec<_> = services
.appservice
.read()
.values()
.filter(|appservice| appservice.is_user_match(&recipient_user))
.cloned()
.collect();
let request = ruma::api::appservice::event::push_events::v1::Request::new(
transaction_id,
vec![pdu.to_format()],
);
for appservice in matching_appservices {
let transaction_id = general_purpose::URL_SAFE_NO_PAD
.encode(sha256::hash(pdu.event_id.as_bytes()))
.into();
services
.sending
.send_appservice_request(appservice.registration.clone(), request)
.await
.map_err(|e| {
error!(
"failed to notify appservice {} about incoming invite: {e}",
appservice.registration.id
);
err!(BadServerResponse(
"Failed to notify appservice about incoming invite."
))
})?;
}
let request = ruma::api::appservice::event::push_events::v1::Request::new(
transaction_id,
vec![pdu.to_format()],
);
services
.sending
.send_appservice_request(appservice.registration.clone(), request)
.await
.map_err(|e| {
error!(
"failed to notify appservice {} about incoming invite: {e}",
appservice.registration.id
);
err!(BadServerResponse("Failed to notify appservice about incoming invite."))
})?;
}
}