chiark / gitweb /
panic handling in webserver task too
[hippotat.git] / server / server.rs
index a10961e2ac81ff3ec6d38f22e098d9904f1f1d83..9ce63aaea8190782d4147f4c2be9e33d423a3ca6 100644 (file)
@@ -165,7 +165,13 @@ async fn main() {
           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")
+              }))
           }) ) }
         }
       );
@@ -200,8 +206,14 @@ async fn main() {
   ).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);
 }