diff --git a/src/service/federation/execute.rs b/src/service/federation/execute.rs index 72486ed89..373c6a6bb 100644 --- a/src/service/federation/execute.rs +++ b/src/service/federation/execute.rs @@ -1,4 +1,5 @@ use std::{ + any::TypeId, borrow::Cow, fmt::Debug, mem, @@ -126,6 +127,7 @@ impl super::Service { where T: OutgoingRequest = PathBuilderInput>> + Send, PathBuilderInput: FederationPathBuilderInput, + ::Authentication: 'static, { if !self.services.server.config.allow_federation { return Err!(Config("allow_federation", "Federation is disabled.")); @@ -137,7 +139,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::() != TypeId::of::(); + if doctor { + self.ensure_remote_is_healthy(dest)?; + } /// How long to wait with re-resolution if a server fails to resolve const UNRESOLVABLE_RETRY_AFTER: Duration = Duration::from_hours(24 * 90); @@ -168,7 +184,8 @@ impl super::Service { self.validate_url(request.url())?; self.services.server.check_running()?; - self.perform::(dest, &actual, request, client).await + self.perform::(dest, &actual, request, client, doctor) + .await } /// Actually sends the federation request, handling the response before @@ -181,6 +198,7 @@ impl super::Service { actual: &Resolution, request: Request, client: &Client, + doctor: bool, ) -> Result where T: OutgoingRequest + Send, @@ -216,8 +234,10 @@ impl super::Service { .record(elapsed.as_secs_f64(), &[KeyValue::new("outcome", outcome)]); match response { | Ok(response) => - self.handle_response::(dest, actual, &method, &url, response) + self.handle_response::(dest, actual, &method, &url, response, doctor) .await, + | Err(error) if !doctor => + Err(handle_error(actual, &method, &url, error).expect_err("always returns error")), | Err(error) => { // This awful wrapping hack is required because `reqwest::Error` // does not implement `Clone`, but we need to convert it @@ -263,6 +283,7 @@ impl super::Service { method: &Method, url: &Url, response: Response, + doctor: bool, ) -> Result where T: OutgoingRequest + Send, @@ -291,13 +312,17 @@ impl super::Service { body.as_ref(), )) .inspect(|_| { - self.mark_healthy(dest); + if doctor { + self.mark_healthy(dest); + } }) .map_err(|e| { - // Bad 200 response is usually a sign of bad routing, so we'll mark - // as stale. We won't mark as offline though since we technically - // got a response. - self.mark_destination_stale(dest); + if doctor { + // Bad 200 response is usually a sign of bad routing, so we'll + // mark as stale. We won't mark as offline though since we + // technically got a response. + self.mark_destination_stale(dest); + } err!(BadServerResponse("Server returned bad 200 response: {e:?}")) }) }