Skip to content

Commit

Permalink
Add error! logs around logrotate errors
Browse files Browse the repository at this point in the history
I'm working on a theory that lading file-gen runs fail because one of the IO
operations that takes place is failing and the error is being silenlty eaten.
Unclear if true. This commit also converts any panics to error returns.

Signed-off-by: Brian L. Troutwine <[email protected]>
  • Loading branch information
blt committed Oct 3, 2024
1 parent 835a918 commit 1d07073
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lading/src/generator/file_gen/logrotate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use tokio::{
sync::mpsc,
task::{JoinError, JoinHandle},
};
use tracing::info;
use tracing::{error, info};

use crate::common::PeekableReceiver;
use lading_payload::block::{self, Block};
Expand All @@ -57,6 +57,9 @@ pub enum Error {
/// Failed to convert, value is 0
#[error("Value provided must not be zero")]
Zero,
/// Name provided but no parent on the path
#[error("Name provided but no parent on the path")]
NameWithNoParent,
}

#[derive(Debug, Deserialize, Serialize, PartialEq)]
Expand Down Expand Up @@ -199,8 +202,14 @@ impl Server {
for res in join_all(self.handles.drain(..)).await {
match res {
Ok(Ok(())) => continue,
Ok(Err(err)) => return Err(err),
Err(err) => return Err(Error::Child(err)),
Ok(Err(err)) => {
error!("join_all error: {err}");
return Err(err);
}
Err(err) => {
error!("logrotate child error: {err}");
return Err(Error::Child(err));
}
}
}
Ok(())
Expand Down Expand Up @@ -263,8 +272,9 @@ impl Child {
.last()
.expect("there is no last element in names");

// SAFETY: By construction the name is guaranteed to have a parent.
fs::create_dir_all(&self.names[0].parent().expect("names has no parent")).await?;
// SAFETY: By construction there is at least one name present.
let parent: &Path = self.names[0].parent().ok_or(Error::NameWithNoParent)?;
fs::create_dir_all(parent).await?;
let mut fp = BufWriter::with_capacity(
bytes_per_second,
fs::OpenOptions::new()
Expand All @@ -281,7 +291,6 @@ impl Child {
let (snd, rcv) = mpsc::channel(1024);
let mut rcv: PeekableReceiver<Block> = PeekableReceiver::new(rcv);
thread::Builder::new().spawn(|| block_cache.spin(snd))?;
let bytes_written = counter!("bytes_written");

let shutdown_wait = self.shutdown.recv();
tokio::pin!(shutdown_wait);
Expand All @@ -298,7 +307,7 @@ impl Child {

{
fp.write_all(&blk.bytes).await?;
bytes_written.increment(total_bytes);
counter!("bytes_written").increment(total_bytes);
total_bytes_written += total_bytes;
}

Expand Down

0 comments on commit 1d07073

Please sign in to comment.