catch panics at base functions to integrate with other fatal errors.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-09-26 04:59:16 +00:00 committed by strawberry
parent 89a3c80700
commit 08a2fecc0e
3 changed files with 26 additions and 11 deletions

1
Cargo.lock generated
View File

@ -763,6 +763,7 @@ dependencies = [
"conduit_core",
"conduit_service",
"const-str",
"futures",
"http",
"http-body-util",
"hyper",

View File

@ -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

View File

@ -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<Server>) -> Pin<Box<dyn Future<Output = Result<Arc<Services>>> + 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<Services>) -> Pin<Box<dyn Future<Output = Result<()>> + 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<Services>) -> Pin<Box<dyn Future<Output = Result<()>> + Send>> {
Box::pin(run::run(services.clone()))
AssertUnwindSafe(run::run(services.clone()))
.catch_unwind()
.map_err(Error::from_panic)
.unwrap_or_else(Err)
.boxed()
}