Skip to content

Commit

Permalink
vex: buffer changes.csv response
Browse files Browse the repository at this point in the history
Moving to the new security domain has surfaced an issue with keeping the
changes.csv connection open long enough for it to be reset-by-peer. This
change buffers the response to file before reading it.

Signed-off-by: crozzy <[email protected]>
  • Loading branch information
crozzy committed Sep 11, 2024
1 parent 85a0988 commit 9e43829
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion rhel/vex/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ func (u *Updater) Fetch(ctx context.Context, hint driver.Fingerprint) (io.ReadCl
// to w means they are deemed to have changed since the compressed
// file was last processed. w and fp can be modified.
func (u *Updater) processChanges(ctx context.Context, w io.Writer, fp *fingerprint) error {
tf, err := tmp.NewFile("", "rhel-vex-changes.")
if err != nil {
return err

Check warning on line 201 in rhel/vex/fetcher.go

View check run for this annotation

Codecov / codecov/patch

rhel/vex/fetcher.go#L201

Added line #L201 was not covered by tests
}
defer tf.Close()

uri, err := u.url.Parse(changesFile)
if err != nil {
return err
Expand Down Expand Up @@ -226,7 +232,15 @@ func (u *Updater) processChanges(ctx context.Context, w io.Writer, fp *fingerpri
}
fp.changesEtag = res.Header.Get("etag")

rd := csv.NewReader(res.Body)
var r io.Reader = res.Body
if _, err := io.Copy(tf, r); err != nil {
return fmt.Errorf("unable to copy resp body to tempfile: %w", err)

Check warning on line 237 in rhel/vex/fetcher.go

View check run for this annotation

Codecov / codecov/patch

rhel/vex/fetcher.go#L237

Added line #L237 was not covered by tests
}
if n, err := tf.Seek(0, io.SeekStart); err != nil || n != 0 {
return fmt.Errorf("unable to seek changes to start: at %d, %v", n, err)

Check warning on line 240 in rhel/vex/fetcher.go

View check run for this annotation

Codecov / codecov/patch

rhel/vex/fetcher.go#L240

Added line #L240 was not covered by tests
}

rd := csv.NewReader(tf)
rd.FieldsPerRecord = 2
rd.ReuseRecord = true
var (
Expand Down

0 comments on commit 9e43829

Please sign in to comment.