let global_ = global_.clone();
let conn = Arc::new(format!("[{}]", conn.remote_addr()));
async { Ok::<_, Void>( hyper::service::service_fn(move |req| {
- sweb::handle(conn.clone(), global_.clone(), req)
+ AssertUnwindSafe(
+ sweb::handle(conn.clone(), global_.clone(), req)
+ )
+ .catch_unwind()
+ .map(|r| r.unwrap_or_else(|_|{
+ crash(Err("panicked".into()), "webserver request task")
+ }))
}) ) }
}
);
).await;
let task = &tasks[died_i].1;
- match output {
- Err(je) => error!("task panicked! {}: {}", task, &je),
- Ok(e) => error!("task failed! {}: {}", task, &e),
+ let output = output.map_err(|je| je.to_string());
+ crash(output, task);
+}
+
+pub fn crash(what_happened: Result<AE, String>, task: &str) -> ! {
+ match what_happened {
+ Err(je) => error!("task crashed! {}: {}", task, &je),
+ Ok(e) => error!("task failed! {}: {}", task, &e ),
}
+ process::exit(12);
}
pub use std::mem;
pub use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
pub use std::path::{Path, PathBuf};
-pub use std::panic;
+pub use std::panic::{self, AssertUnwindSafe};
pub use std::process;
pub use std::pin::Pin;
pub use std::str::{self, FromStr};
pub use tokio::pin;
pub use tokio::select;
pub use tokio::sync::{mpsc, oneshot};
-pub use tokio::task::{self, JoinHandle};
+pub use tokio::task::{self, JoinError, JoinHandle};
pub use tokio::time::{Duration, Instant};
pub use void::{self, Void, ResultVoidExt, ResultVoidErrExt};