Make spawn_essential_task more strict (#4198)

This commit is contained in:
Pierre Krieger
2019-11-25 17:48:25 +01:00
committed by Bastian Köcher
parent d7b9dd300b
commit d8ca2f37df
+7 -4
View File
@@ -240,10 +240,13 @@ where
fn spawn_essential_task(&self, task: impl Future<Item = (), Error = ()> + Send + 'static) {
let essential_failed = self.essential_failed.clone();
let essential_task = task.map_err(move |_| {
error!("Essential task failed. Shutting down service.");
essential_failed.store(true, Ordering::Relaxed);
});
let essential_task = std::panic::AssertUnwindSafe(task)
.catch_unwind()
.then(move |_| {
error!("Essential task failed. Shutting down service.");
essential_failed.store(true, Ordering::Relaxed);
Ok(())
});
let task = essential_task.select(self.on_exit()).then(|_| Ok(()));
let _ = self.to_spawn_tx.unbounded_send(Box::new(task));