catch panics at base functions to integrate with other fatal errors.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
89a3c80700
commit
08a2fecc0e
3 changed files with 26 additions and 11 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -763,6 +763,7 @@ dependencies = [
|
||||||
"conduit_core",
|
"conduit_core",
|
||||||
"conduit_service",
|
"conduit_service",
|
||||||
"const-str",
|
"const-str",
|
||||||
|
"futures",
|
||||||
"http",
|
"http",
|
||||||
"http-body-util",
|
"http-body-util",
|
||||||
"hyper",
|
"hyper",
|
||||||
|
|
|
@ -54,20 +54,18 @@ axum-server-dual-protocol.workspace = true
|
||||||
axum-server-dual-protocol.optional = true
|
axum-server-dual-protocol.optional = true
|
||||||
axum-server.workspace = true
|
axum-server.workspace = true
|
||||||
axum.workspace = true
|
axum.workspace = true
|
||||||
|
bytes.workspace = true
|
||||||
conduit-admin.workspace = true
|
conduit-admin.workspace = true
|
||||||
conduit-api.workspace = true
|
conduit-api.workspace = true
|
||||||
conduit-core.workspace = true
|
conduit-core.workspace = true
|
||||||
conduit-service.workspace = true
|
conduit-service.workspace = true
|
||||||
const-str.workspace = true
|
const-str.workspace = true
|
||||||
log.workspace = true
|
futures.workspace = true
|
||||||
tokio.workspace = true
|
|
||||||
tower.workspace = true
|
|
||||||
tracing.workspace = true
|
|
||||||
bytes.workspace = true
|
|
||||||
http-body-util.workspace = true
|
|
||||||
http.workspace = true
|
http.workspace = true
|
||||||
|
http-body-util.workspace = true
|
||||||
hyper.workspace = true
|
hyper.workspace = true
|
||||||
hyper-util.workspace = true
|
hyper-util.workspace = true
|
||||||
|
log.workspace = true
|
||||||
ruma.workspace = true
|
ruma.workspace = true
|
||||||
rustls.workspace = true
|
rustls.workspace = true
|
||||||
rustls.optional = true
|
rustls.optional = true
|
||||||
|
@ -78,7 +76,10 @@ sentry-tracing.optional = true
|
||||||
sentry-tracing.workspace = true
|
sentry-tracing.workspace = true
|
||||||
sentry.workspace = true
|
sentry.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
|
tokio.workspace = true
|
||||||
|
tower.workspace = true
|
||||||
tower-http.workspace = true
|
tower-http.workspace = true
|
||||||
|
tracing.workspace = true
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
sd-notify.workspace = true
|
sd-notify.workspace = true
|
||||||
|
|
|
@ -6,10 +6,11 @@ mod serve;
|
||||||
|
|
||||||
extern crate conduit_core as conduit;
|
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 conduit_service::Services;
|
||||||
|
use futures::{Future, FutureExt, TryFutureExt};
|
||||||
|
|
||||||
conduit::mod_ctor! {}
|
conduit::mod_ctor! {}
|
||||||
conduit::mod_dtor! {}
|
conduit::mod_dtor! {}
|
||||||
|
@ -17,15 +18,27 @@ conduit::rustc_flags_capture! {}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "Rust" fn start(server: &Arc<Server>) -> Pin<Box<dyn Future<Output = Result<Arc<Services>>> + Send>> {
|
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]
|
#[no_mangle]
|
||||||
pub extern "Rust" fn stop(services: Arc<Services>) -> Pin<Box<dyn Future<Output = Result<()>> + Send>> {
|
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]
|
#[no_mangle]
|
||||||
pub extern "Rust" fn run(services: &Arc<Services>) -> Pin<Box<dyn Future<Output = Result<()>> + Send>> {
|
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()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue