Compare commits

...
Author SHA1 Message Date
timedout d81f65c4aa fix: Don't flag remotes as un/healty as a result of authless requests
This would break the sender flush in the request auth handler since marking a server as healthy after it was already healthy makes `mark_healthy` return `false`, so the flush would never run.
2026-12-04 12:35:07 +00:00
timedout b305b765f1 fix: Don't check health for unsigned requests 2026-12-04 12:21:05 +00:00
+33 -8
View File
@@ -1,4 +1,5 @@
use std::{ use std::{
any::TypeId,
borrow::Cow, borrow::Cow,
fmt::Debug, fmt::Debug,
mem, mem,
@@ -125,6 +126,7 @@ impl super::Service {
where where
T: OutgoingRequest<PathBuilder: PathBuilder<Input<'i> = PathBuilderInput>> + Send, T: OutgoingRequest<PathBuilder: PathBuilder<Input<'i> = PathBuilderInput>> + Send,
PathBuilderInput: FederationPathBuilderInput, PathBuilderInput: FederationPathBuilderInput,
<T as ruma::api::Metadata>::Authentication: 'static,
{ {
if !self.services.server.config.allow_federation { if !self.services.server.config.allow_federation {
return Err!(Config("allow_federation", "Federation is disabled.")); return Err!(Config("allow_federation", "Federation is disabled."));
@@ -136,7 +138,21 @@ impl super::Service {
)))); ))));
} }
self.ensure_remote_is_healthy(dest)?; // Don't check health on unauthenticated requests, since those are only
// for keys and manual pings, which want to bypass health tracking
// anyway.
//
// TODO(nex): We should probably do a proper builder pattern for
// requests, since callers may wish to tune
// - Authentication (signed vs unsigned)
// - Health check activity
// - Timeout (normal vs slow)
// and having a billion functions and conditions for all of those is not
// ideal.
let doctor = TypeId::of::<T::Authentication>() != TypeId::of::<NoAuthentication>();
if doctor {
self.ensure_remote_is_healthy(dest)?;
}
/// How long to wait with re-resolution if a server fails to resolve /// How long to wait with re-resolution if a server fails to resolve
const UNRESOLVABLE_RETRY_AFTER: Duration = Duration::from_hours(24 * 90); const UNRESOLVABLE_RETRY_AFTER: Duration = Duration::from_hours(24 * 90);
@@ -160,7 +176,8 @@ impl super::Service {
self.validate_url(request.url())?; self.validate_url(request.url())?;
self.services.server.check_running()?; self.services.server.check_running()?;
self.perform::<T>(dest, &actual, request, client).await self.perform::<T>(dest, &actual, request, client, doctor)
.await
} }
/// Actually sends the federation request, handling the response before /// Actually sends the federation request, handling the response before
@@ -173,6 +190,7 @@ impl super::Service {
actual: &Resolution, actual: &Resolution,
request: Request, request: Request,
client: &Client, client: &Client,
doctor: bool,
) -> Result<T::IncomingResponse> ) -> Result<T::IncomingResponse>
where where
T: OutgoingRequest + Send, T: OutgoingRequest + Send,
@@ -208,8 +226,10 @@ impl super::Service {
.record(elapsed.as_secs_f64(), &[KeyValue::new("outcome", outcome)]); .record(elapsed.as_secs_f64(), &[KeyValue::new("outcome", outcome)]);
match response { match response {
| Ok(response) => | Ok(response) =>
self.handle_response::<T>(dest, actual, &method, &url, response) self.handle_response::<T>(dest, actual, &method, &url, response, doctor)
.await, .await,
| Err(error) if !doctor =>
Err(handle_error(actual, &method, &url, error).expect_err("always returns error")),
| Err(error) => { | Err(error) => {
// This awful wrapping hack is required because `reqwest::Error` // This awful wrapping hack is required because `reqwest::Error`
// does not implement `Clone`, but we need to convert it // does not implement `Clone`, but we need to convert it
@@ -255,6 +275,7 @@ impl super::Service {
method: &Method, method: &Method,
url: &Url, url: &Url,
response: Response, response: Response,
doctor: bool,
) -> Result<T::IncomingResponse> ) -> Result<T::IncomingResponse>
where where
T: OutgoingRequest + Send, T: OutgoingRequest + Send,
@@ -283,13 +304,17 @@ impl super::Service {
body.as_ref(), body.as_ref(),
)) ))
.inspect(|_| { .inspect(|_| {
self.mark_healthy(dest); if doctor {
self.mark_healthy(dest);
}
}) })
.map_err(|e| { .map_err(|e| {
// Bad 200 response is usually a sign of bad routing, so we'll mark if doctor {
// as stale. We won't mark as offline though since we technically // Bad 200 response is usually a sign of bad routing, so we'll
// got a response. // mark as stale. We won't mark as offline though since we
self.mark_destination_stale(dest); // technically got a response.
self.mark_destination_stale(dest);
}
err!(BadServerResponse("Server returned bad 200 response: {e:?}")) err!(BadServerResponse("Server returned bad 200 response: {e:?}"))
}) })
} }