From b2a565b0b4e32cf998ee5877cecded31f1305240 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 26 Jan 2025 15:44:52 +0000 Subject: [PATCH] propagate better error from server.check_running() --- src/core/error/response.rs | 1 + src/core/server.rs | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/error/response.rs b/src/core/error/response.rs index ede1a05d..75e4050d 100644 --- a/src/core/error/response.rs +++ b/src/core/error/response.rs @@ -106,6 +106,7 @@ pub(super) fn io_error_code(kind: std::io::ErrorKind) -> StatusCode { | ErrorKind::TimedOut => StatusCode::GATEWAY_TIMEOUT, | ErrorKind::FileTooLarge => StatusCode::PAYLOAD_TOO_LARGE, | ErrorKind::StorageFull => StatusCode::INSUFFICIENT_STORAGE, + | ErrorKind::Interrupted => StatusCode::SERVICE_UNAVAILABLE, | _ => StatusCode::INTERNAL_SERVER_ERROR, } } diff --git a/src/core/server.rs b/src/core/server.rs index 05a4aae7..0f2e61b0 100644 --- a/src/core/server.rs +++ b/src/core/server.rs @@ -9,7 +9,7 @@ use std::{ use ruma::OwnedServerName; use tokio::{runtime, sync::broadcast}; -use crate::{config, config::Config, err, log::Log, metrics::Metrics, Err, Result}; +use crate::{config, config::Config, log::Log, metrics::Metrics, Err, Result}; /// Server runtime state; public portion pub struct Server { @@ -127,9 +127,12 @@ impl Server { #[inline] pub fn check_running(&self) -> Result { + use std::{io, io::ErrorKind::Interrupted}; + self.running() .then_some(()) - .ok_or_else(|| err!(debug_warn!("Server is shutting down."))) + .ok_or_else(|| io::Error::new(Interrupted, "Server shutting down")) + .map_err(Into::into) } #[inline]