From 87403141241f3d6958d0c4512fcd93a676565f04 Mon Sep 17 00:00:00 2001 From: haixuanTao Date: Wed, 3 May 2023 19:11:50 +0800 Subject: [PATCH] Wait for logs to be logged before exiting daemon In previous iteration of logging, the logging thread was not waited for and the daemon would exit before finishing to log all lines causing a panic. See: https://github.com/dora-rs/dora/actions/runs/4805449241/jobs/8551873559#step:11:619 --- binaries/coordinator/src/lib.rs | 3 ++- binaries/daemon/src/spawn.rs | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/binaries/coordinator/src/lib.rs b/binaries/coordinator/src/lib.rs index 95f70db3..c9ad5ed5 100644 --- a/binaries/coordinator/src/lib.rs +++ b/binaries/coordinator/src/lib.rs @@ -109,7 +109,8 @@ fn resolve_name( } else if let [uuid] = archived_uuids.as_slice() { Ok(*uuid) } else { - bail!("multiple archived dataflows found with name `{name}`"); + // TOOD: Index the archived dataflows in order to return logs based on the index. + bail!("multiple archived dataflows found with name `{name}`, Please provide the UUID instead."); } } else if let [uuid] = uuids.as_slice() { Ok(*uuid) diff --git a/binaries/daemon/src/spawn.rs b/binaries/daemon/src/spawn.rs index 91853aab..0755282a 100644 --- a/binaries/daemon/src/spawn.rs +++ b/binaries/daemon/src/spawn.rs @@ -17,7 +17,7 @@ use std::{ use tokio::{ fs::File, io::{AsyncBufReadExt, AsyncWriteExt}, - sync::mpsc, + sync::{mpsc, oneshot}, }; use tracing::{debug, error}; @@ -213,14 +213,15 @@ pub async fn spawn_node( } }); + let (log_finish_tx, log_finish_rx) = oneshot::channel(); tokio::spawn(async move { let exit_status = NodeExitStatus::from(child.wait().await); + let _ = log_finish_rx.await; let event = DoraEvent::SpawnedNodeResult { dataflow_id, node_id, exit_status, }; - let _ = daemon_tx.send(event.into()).await; }); @@ -242,6 +243,9 @@ pub async fn spawn_node( .await .map_err(|err| error!("Could not sync logs to file due to {err}")); } + let _ = log_finish_tx + .send(()) + .map_err(|_| error!("Could not inform that log file thread finished")); }); Ok(()) }