1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-07-27 18:28:31 +00:00

feat(policy-server): Limit policy server request timeout to 10 seconds

This commit is contained in:
nexy7574 2025-07-19 22:07:18 +01:00
parent a3d62ed0d9
commit cc9202b0c4
No known key found for this signature in database
GPG key ID: 0FA334385D0B689F

View file

@ -1,3 +1,5 @@
use std::time::Duration;
use conduwuit::{Err, Event, PduEvent, Result, debug, implement, warn}; use conduwuit::{Err, Event, PduEvent, Result, debug, implement, warn};
use ruma::{ use ruma::{
RoomId, ServerName, RoomId, ServerName,
@ -32,17 +34,19 @@ pub async fn policyserv_check(&self, pdu: &PduEvent, room_id: &RoomId) -> Result
.convert_to_outgoing_federation_event(pdu.to_canonical_object()) .convert_to_outgoing_federation_event(pdu.to_canonical_object())
.await; .await;
debug!("Checking pdu {outgoing:?} for spam with policy server {via} for room {room_id}"); debug!("Checking pdu {outgoing:?} for spam with policy server {via} for room {room_id}");
let response = self let response = tokio::time::timeout(
.services Duration::from_secs(10),
self.services
.sending .sending
.send_federation_request(via, PolicyRequest { .send_federation_request(via, PolicyRequest {
event_id: pdu.event_id().to_owned(), event_id: pdu.event_id().to_owned(),
pdu: Some(outgoing), pdu: Some(outgoing),
}) }),
)
.await; .await;
let response = match response { let response = match response {
| Ok(response) => response, | Ok(Ok(response)) => response,
| Err(e) => { | Ok(Err(e)) => {
warn!( warn!(
via = %via, via = %via,
event_id = %pdu.event_id(), event_id = %pdu.event_id(),
@ -51,6 +55,15 @@ pub async fn policyserv_check(&self, pdu: &PduEvent, room_id: &RoomId) -> Result
); );
return Ok(()); return Ok(());
}, },
| Err(_) => {
warn!(
via = %via,
event_id = %pdu.event_id(),
room_id = %room_id,
"Policy server request timed out after 10 seconds"
);
return Ok(());
},
}; };
if response.recommendation == "spam" { if response.recommendation == "spam" {
warn!( warn!(