Skip to content

Commit

Permalink
output: forget the metrics File inside the BufWriter (iopsystems#256)
Browse files Browse the repository at this point in the history
The output file has a reference held by both the BufWriter
as well as the NamedTempFile, which results in both of them
attempting to close it and a fatal runtime error: "IO Safety
violation: owned file descriptor already closed".

Forget the file inside the BufWriter, so it is only closed
when the NamedTempFile is finished with it.
  • Loading branch information
mihirn authored Aug 20, 2024
1 parent fb486be commit 8182175
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,18 @@ pub async fn metrics(config: Config) {
Snapshot::to_msgpack(&snapshot).expect("failed to serialize")
}
};
let _ = writer.write_all(&buf).await;
if let Err(e) = writer.write_all(&buf).await {
eprintln!("error writing metrics output: {}", e);
std::process::exit(1);
}
}

if let Err(e) = writer.flush().await {
eprintln!("error writing metrics output: {}", e);
std::process::exit(1);
}

let _ = writer.flush().await;
drop(writer);
std::mem::forget(writer.into_inner());

// Post-process metrics into a parquet file
if metrics_config.format() == MetricsFormat::Parquet {
Expand Down

0 comments on commit 8182175

Please sign in to comment.