Skip to content

Commit 266b629

Browse files
authored
Flush support bundle logs when copied from stream (#8716)
Fixes #8711
1 parent 62c33c8 commit 266b629

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

nexus/src/app/background/tasks/support_bundle_collector.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use std::num::NonZeroU64;
5151
use std::sync::Arc;
5252
use tokio::io::AsyncReadExt;
5353
use tokio::io::AsyncSeekExt;
54+
use tokio::io::AsyncWriteExt;
5455
use tokio::io::SeekFrom;
5556
use tufaceous_artifact::ArtifactHash;
5657
use zip::ZipArchive;
@@ -983,29 +984,30 @@ async fn save_zone_log_zip_or_error(
983984
Ok(res) => {
984985
let bytestream = res.into_inner();
985986
let output_dir = path.join(format!("logs/{zone}"));
986-
let output_file = output_dir.join("logs.zip");
987+
let output_path = output_dir.join("logs.zip");
987988

988989
// Ensure the logs output directory exists.
989990
tokio::fs::create_dir_all(&output_dir).await.with_context(
990991
|| format!("failed to create output directory: {output_dir}"),
991992
)?;
992993

993994
let mut file =
994-
tokio::fs::File::create(&output_file).await.with_context(
995-
|| format!("failed to create file: {output_file}"),
995+
tokio::fs::File::create(&output_path).await.with_context(
996+
|| format!("failed to create file: {output_path}"),
996997
)?;
997998

998999
let stream = bytestream.into_inner().map(|chunk| {
9991000
chunk.map_err(|e| std::io::Error::other(e.to_string()))
10001001
});
10011002
let mut reader = tokio_util::io::StreamReader::new(stream);
10021003
let _nbytes = tokio::io::copy(&mut reader, &mut file).await?;
1004+
file.flush().await?;
10031005

10041006
// Unpack the zip so we don't end up with zip files inside of our
10051007
// final zip
1006-
let zipfile = output_file.clone();
1008+
let zipfile_path = output_path.clone();
10071009
tokio::task::spawn_blocking(move || {
1008-
extract_zip_file(&output_dir, &zipfile)
1010+
extract_zip_file(&output_dir, &zipfile_path)
10091011
})
10101012
.await
10111013
.map_err(|join_error| {
@@ -1014,12 +1016,12 @@ async fn save_zone_log_zip_or_error(
10141016
})??;
10151017

10161018
// Cleanup the zip file since we no longer need it
1017-
if let Err(e) = tokio::fs::remove_file(&output_file).await {
1019+
if let Err(e) = tokio::fs::remove_file(&output_path).await {
10181020
error!(
10191021
logger,
10201022
"failed to cleanup temporary logs zip file";
10211023
"error" => %e,
1022-
"file" => %output_file,
1024+
"file" => %output_path,
10231025

10241026
);
10251027
}

0 commit comments

Comments
 (0)