Skip to content

Commit

Permalink
Bugfix: Close zip container before final progress write.
Browse files Browse the repository at this point in the history
This ensures the hash is written in every case.
  • Loading branch information
scudette committed Jan 3, 2025
1 parent 8e7c57b commit 76766c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion json/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func ConvertJSONL(

// In the special case where we do not need to modify the json
// or convert it to csv then we can skip parsing it
// alltogether.
// altogether.
if extra_data == nil && jsonl_out != nil && csv_out == nil {
jsonl_out.Write(serialized)
continue
Expand Down
3 changes: 3 additions & 0 deletions reporting/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func (self *progressReporter) writeStats() {
// If we call Close() before the timeout then the collection worked
// fine - even when the context is cancelled.
func (self *progressReporter) Close() {
// Write the stats one final time.
self.writeStats()

self.mu.Lock()
defer self.mu.Unlock()

Expand Down
14 changes: 8 additions & 6 deletions vql/server/downloads/downloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,6 @@ func createDownloadFile(
go func() {
defer wg.Done()

// Will also close the underlying container when done.
defer zip_writer.Close()

timeout := int64(600)
if config_obj.Defaults != nil &&
config_obj.Defaults.ExportMaxTimeoutSec > 0 {
Expand All @@ -265,6 +262,10 @@ func createDownloadFile(
download_file, zip_writer)
defer progress_reporter.Close()

// Will also close the underlying container when done. Must be
// done before progress close so we can write the hash.
defer zip_writer.Close()

err := downloadFlowToZip(ctx, scope, config_obj, format,
client_id, path_specs.NewUnsafeFilestorePath(),
flow_id, expand_sparse, zip_writer)
Expand Down Expand Up @@ -775,9 +776,6 @@ func createHuntDownloadFile(
go func() {
defer wg.Done()

// Will also close the underlying fd.
defer zip_writer.Close()

timeout := int64(3600)
if config_obj.Defaults != nil &&
config_obj.Defaults.ExportMaxTimeoutSec > 0 {
Expand All @@ -795,6 +793,10 @@ func createHuntDownloadFile(
download_file, zip_writer)
defer progress_reporter.Close()

// Will also close the underlying container when done. Must be
// done before progress close so we can write the hash.
defer zip_writer.Close()

err = zip_writer.WriteJSON(
paths.ZipPathFromFSPathSpec(path_specs.NewUnsafeFilestorePath().AddChild("hunt_info")),
hunt_details)
Expand Down

0 comments on commit 76766c2

Please sign in to comment.