diff --git a/libbeat/reader/readfile/line.go b/libbeat/reader/readfile/line.go index e13b2a8fb00d..c36832e514e4 100644 --- a/libbeat/reader/readfile/line.go +++ b/libbeat/reader/readfile/line.go @@ -88,7 +88,10 @@ func (r *LineReader) Next() (b []byte, n int, err error) { // read next 'potential' line from input buffer/reader err := r.advance() if err != nil { - return nil, 0, err + // return and reset consumed bytes count + sz := r.byteCount + r.byteCount = 0 + return nil, sz, err } // Check last decoded byte really being newline also unencoded diff --git a/libbeat/reader/readfile/line_test.go b/libbeat/reader/readfile/line_test.go index 68f257bf45db..85323ea32c20 100644 --- a/libbeat/reader/readfile/line_test.go +++ b/libbeat/reader/readfile/line_test.go @@ -373,6 +373,7 @@ func TestMaxBytesLimit(t *testing.T) { b, n, err := reader.Next() if err != nil { if err == io.EOF { + readLen += n break } else { t.Fatal("unexpected error:", err)