From 5f5eca6b8e83894f0e403bfba30a828d48a699db Mon Sep 17 00:00:00 2001 From: bin Date: Mon, 25 Oct 2021 18:19:51 +0800 Subject: [PATCH] agent: do not return error but print it if task wait failed Do not return error but print it if task wait failed and let program continue to run the next code. Fixes: #2892 Signed-off-by: bin --- src/agent/src/main.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index d62f9670c4..c2ae8c7697 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -229,12 +229,6 @@ async fn real_main() -> std::result::Result<(), Box> { // Wait for all threads to finish let results = join_all(tasks).await; - for result in results { - if let Err(e) = result { - return Err(anyhow!(e).into()); - } - } - // force flushing spans drop(span_guard); drop(root_span); @@ -245,7 +239,19 @@ async fn real_main() -> std::result::Result<(), Box> { eprintln!("{} shutdown complete", NAME); - Ok(()) + let mut wait_errors: Vec = vec![]; + for result in results { + if let Err(e) = result { + eprintln!("wait task error: {:#?}", e); + wait_errors.push(e); + } + } + + if wait_errors.is_empty() { + Ok(()) + } else { + Err(anyhow!("wait all tasks failed: {:#?}", wait_errors).into()) + } } fn main() -> std::result::Result<(), Box> {