Skip to content

Commit

Permalink
Fix lapsus with envoyx json decoder
Browse files Browse the repository at this point in the history
The decoder's reset didn't reset because we used an incorrect
reader and didn't reload the JSON decoder.
  • Loading branch information
tjerman committed Oct 16, 2023
1 parent 399f9a7 commit 532e1ac
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions server/pkg/envoyx/json/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func Decoder(r io.Reader, ident string) (out *decoder, err error) {
return
}

r, err = out.flushTemp(r)
err = out.flushTemp(r)
defer out.src.Seek(0, 0)
if err != nil {
return
}

out.reader = json.NewDecoder(r)
out.reader = json.NewDecoder(out.src)

seenHeader := make(map[string]bool)

Expand Down Expand Up @@ -113,7 +113,12 @@ func (d *decoder) Fields() []string {
// Reset resets the decoder to the start
func (d *decoder) Reset(_ context.Context) error {
_, err := d.src.Seek(0, 0)
return err
if err != nil {
return err
}

d.reader = json.NewDecoder(d.src)
return nil
}

// Next returns the field: value mapping for the next row
Expand All @@ -140,12 +145,12 @@ func (d *decoder) Count() uint64 {
return d.count
}

func (d *decoder) flushTemp(r io.Reader) (_ io.Reader, err error) {
func (d *decoder) flushTemp(r io.Reader) (err error) {
_, err = io.Copy(d.src, r)
if err != nil {
return
}

d.src.Seek(0, 0)
return d.src, nil
return nil
}

0 comments on commit 532e1ac

Please sign in to comment.