From 56e424a7cee0b830b94e5fda5ff6a0436680b852 Mon Sep 17 00:00:00 2001 From: William Findlay Date: Fri, 9 Dec 2022 15:04:33 -0500 Subject: [PATCH] jsonchecker: retry on EOF/UnexpectedEOF in unmarshaller I ran into a corner case in CI a few times where it seems that the exporter is in the middle of writing an event when the jsonchecker decides to open the file and check it. In this case, the unmarshaller will bubble up either an EOF or UnexpectedEOF error which will fail the test. To handle this, let's just treat these errors the same way we treat regular JSON EOF: by retrying after a few seconds. Signed-off-by: William Findlay --- pkg/jsonchecker/jsonchecker.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/jsonchecker/jsonchecker.go b/pkg/jsonchecker/jsonchecker.go index ff3722fe2f4..55707fd8a20 100644 --- a/pkg/jsonchecker/jsonchecker.go +++ b/pkg/jsonchecker/jsonchecker.go @@ -80,6 +80,12 @@ func JsonCheck(jsonFile *os.File, checker ec.MultiEventChecker, log *logrus.Logg var dbgErr *DebugError var ev tetragon.GetEventsResponse if err := dec.Decode(&ev); err != nil { + if errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, io.EOF) { + return &JsonEOF{ + count: count, + err: fmt.Errorf("unmarshal failed: %w", err), + } + } return fmt.Errorf("unmarshal failed: %w", err) } count++