From 89a113cb5dc61d0d28d177e9f3a12a2345367c6b Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin <valyala@gmail.com> Date: Fri, 7 Jun 2019 23:36:58 +0300 Subject: [PATCH] app/vminsert: really fix #60 ReadLinesBlock may accept dstBuf with non-zero length. In this case the last line without trailing newline isn't read. Fix this by comparing len(dstBuf) to 0 instead of its original length. --- app/vminsert/common/lines_reader.go | 3 +-- app/vminsert/common/lines_reader_test.go | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/vminsert/common/lines_reader.go b/app/vminsert/common/lines_reader.go index 4f28bf8454..17c620d42f 100644 --- a/app/vminsert/common/lines_reader.go +++ b/app/vminsert/common/lines_reader.go @@ -20,7 +20,6 @@ const defaultBlockSize = 64 * 1024 // // Returns (dstBuf, tailBuf). func ReadLinesBlock(r io.Reader, dstBuf, tailBuf []byte) ([]byte, []byte, error) { - origDstBufLen := len(dstBuf) if cap(dstBuf) < defaultBlockSize { dstBuf = bytesutil.Resize(dstBuf, defaultBlockSize) } @@ -33,7 +32,7 @@ again: if err == nil { return dstBuf, tailBuf, fmt.Errorf("no forward progress made") } - if err == io.EOF && len(dstBuf) > origDstBufLen { + if err == io.EOF && len(dstBuf) > 0 { // Missing newline in the end of stream. This is OK, /// so suppress io.EOF for now. It will be returned during the next // call to ReadLinesBlock. diff --git a/app/vminsert/common/lines_reader_test.go b/app/vminsert/common/lines_reader_test.go index 6c3d304c3f..d0386fd139 100644 --- a/app/vminsert/common/lines_reader_test.go +++ b/app/vminsert/common/lines_reader_test.go @@ -79,6 +79,7 @@ func TestReadLineBlockSuccessSingleByteReader(t *testing.T) { f("\nfoo", "", "") f("foo\nbar", "foo", "") f("foo\nbar\nbaz", "foo", "") + f("foo", "foo", "") // The maximum line size b := make([]byte, maxLineSize+10)