diff --git a/Cargo.lock b/Cargo.lock index e72c7e80..b9f366e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -763,6 +763,7 @@ dependencies = [ "conduit_core", "conduit_service", "const-str", + "futures", "http", "http-body-util", "hyper", diff --git a/src/router/Cargo.toml b/src/router/Cargo.toml index 62690194..e1535868 100644 --- a/src/router/Cargo.toml +++ b/src/router/Cargo.toml @@ -54,20 +54,18 @@ axum-server-dual-protocol.workspace = true axum-server-dual-protocol.optional = true axum-server.workspace = true axum.workspace = true +bytes.workspace = true conduit-admin.workspace = true conduit-api.workspace = true conduit-core.workspace = true conduit-service.workspace = true const-str.workspace = true -log.workspace = true -tokio.workspace = true -tower.workspace = true -tracing.workspace = true -bytes.workspace = true -http-body-util.workspace = true +futures.workspace = true http.workspace = true +http-body-util.workspace = true hyper.workspace = true hyper-util.workspace = true +log.workspace = true ruma.workspace = true rustls.workspace = true rustls.optional = true @@ -78,7 +76,10 @@ sentry-tracing.optional = true sentry-tracing.workspace = true sentry.workspace = true serde_json.workspace = true +tokio.workspace = true +tower.workspace = true tower-http.workspace = true +tracing.workspace = true [target.'cfg(unix)'.dependencies] sd-notify.workspace = true diff --git a/src/router/mod.rs b/src/router/mod.rs index e123442c..1580f605 100644 --- a/src/router/mod.rs +++ b/src/router/mod.rs @@ -6,10 +6,11 @@ mod serve; extern crate conduit_core as conduit; -use std::{future::Future, pin::Pin, sync::Arc}; +use std::{panic::AssertUnwindSafe, pin::Pin, sync::Arc}; -use conduit::{Result, Server}; +use conduit::{Error, Result, Server}; use conduit_service::Services; +use futures::{Future, FutureExt, TryFutureExt}; conduit::mod_ctor! {} conduit::mod_dtor! {} @@ -17,15 +18,27 @@ conduit::rustc_flags_capture! {} #[no_mangle] pub extern "Rust" fn start(server: &Arc) -> Pin>> + Send>> { - Box::pin(run::start(server.clone())) + AssertUnwindSafe(run::start(server.clone())) + .catch_unwind() + .map_err(Error::from_panic) + .unwrap_or_else(Err) + .boxed() } #[no_mangle] pub extern "Rust" fn stop(services: Arc) -> Pin> + Send>> { - Box::pin(run::stop(services)) + AssertUnwindSafe(run::stop(services)) + .catch_unwind() + .map_err(Error::from_panic) + .unwrap_or_else(Err) + .boxed() } #[no_mangle] pub extern "Rust" fn run(services: &Arc) -> Pin> + Send>> { - Box::pin(run::run(services.clone())) + AssertUnwindSafe(run::run(services.clone())) + .catch_unwind() + .map_err(Error::from_panic) + .unwrap_or_else(Err) + .boxed() }