feat: Enable shutdown interrupt in ratelimit handler

This commit is contained in:
timedout
2026-05-21 19:06:16 +01:00
parent e0fe71c708
commit 1c88854a54
2 changed files with 9 additions and 2 deletions
+5
View File
@@ -19,6 +19,7 @@ use ruma::{
OwnedEventId, OwnedRoomId, RoomId, events::room::create::RoomCreateEventContent,
room_version_rules::RoomVersionRules,
};
use tokio::sync::Notify;
use crate::{Dep, globals, rooms, sending, server_keys};
@@ -26,6 +27,7 @@ pub struct Service {
pub mutex_federation: RoomMutexMap,
pub federation_handletime: SyncRwLock<HandleTimeMap>,
services: Services,
server_shutdown: Notify,
}
struct Services {
@@ -72,6 +74,7 @@ impl crate::Service for Service {
timeline: args.depend::<rooms::timeline::Service>("rooms::timeline"),
server: args.server.clone(),
},
server_shutdown: Notify::new(),
}))
}
@@ -86,6 +89,8 @@ impl crate::Service for Service {
}
fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
fn interrupt(&self) { self.server_shutdown.notify_waiters(); }
}
impl Service {
@@ -259,8 +259,10 @@ async fn handle_policy_server_error(
retries,
"Policy server rate-limited us; retrying after {retry_after:?}"
);
// TODO: select between this sleep and shutdown signal
sleep(saturated).await;
tokio::select! {
() = self.server_shutdown.notified() => (),
() = sleep(saturated) => (),
}
if !self.services.server.running() {
return Err(error);
}