Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: flush BufWriter #22

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use tokio::{
io::{self, AsyncBufRead, AsyncBufReadExt, AsyncWrite, AsyncWriteExt, BufReader, BufWriter},
};
use tokio_stream::StreamExt;
use tracing::trace;
use tracing_subscriber::{fmt::format::FmtSpan, layer::SubscriberExt, util::SubscriberInitExt};
use types::{BasinConfig, StreamConfig, RETENTION_POLICY_PATH, STORAGE_CLASS_PATH};

Expand Down Expand Up @@ -237,16 +238,20 @@ impl RecordsIO {
pub async fn into_writer(&self) -> io::Result<Box<dyn AsyncWrite + Send + Unpin>> {
match self {
RecordsIO::File(path) => {
trace!(?path, "opening file writer");
let file = OpenOptions::new()
.write(true)
.create(true)
.append(true)
.open(path)
.await?;

Ok(Box::new(tokio::io::BufWriter::new(file)))
Ok(Box::new(BufWriter::new(file)))
}
RecordsIO::Stdout => {
trace!("stdout writer");
Ok(Box::new(BufWriter::new(tokio::io::stdout())))
}
RecordsIO::Stdout => Ok(Box::new(BufWriter::new(tokio::io::stdout()))),
RecordsIO::Stdin => panic!("unsupported record source"),
}
}
Expand Down Expand Up @@ -538,6 +543,9 @@ async fn run() -> Result<(), S2CliError> {
);
}
}
if let Some(ref mut writer) = writer {
writer.flush().await.expect("writer flush");
}
Comment on lines 545 to +548
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it not write anything to stdout? and if you ctrl + c, does it not write anything?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was not writing anything to stdout earlier, even if ctrl-c'ing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am not sure then what i was seeing when i was testing this. thanks for finding and fixing this!

}
}
}
Expand Down