From 7cd2c0da7a2c7f6c18b653d145b38cdaf261a33b Mon Sep 17 00:00:00 2001 From: liuwenping Date: Thu, 9 Jun 2022 11:54:09 +0800 Subject: [PATCH] [Filebeat] keep track of bytes read when max_bytes exceeded in the last line --- libbeat/reader/readfile/line.go | 5 ++++- libbeat/reader/readfile/line_test.go | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) 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)