Browse Source

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
tags/v0.2.3-rc
haixuanTao 2 years ago
parent
commit
8740314124
2 changed files with 8 additions and 3 deletions
  1. +2
    -1
      binaries/coordinator/src/lib.rs
  2. +6
    -2
      binaries/daemon/src/spawn.rs

+ 2
- 1
binaries/coordinator/src/lib.rs View File

@@ -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)


+ 6
- 2
binaries/daemon/src/spawn.rs View File

@@ -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(())
}

Loading…
Cancel
Save