mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
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.
This commit is contained in:
parent
0b78d228d2
commit
f4252f87e6
2 changed files with 2 additions and 2 deletions
|
@ -20,7 +20,6 @@ const defaultBlockSize = 64 * 1024
|
||||||
//
|
//
|
||||||
// Returns (dstBuf, tailBuf).
|
// Returns (dstBuf, tailBuf).
|
||||||
func ReadLinesBlock(r io.Reader, dstBuf, tailBuf []byte) ([]byte, []byte, error) {
|
func ReadLinesBlock(r io.Reader, dstBuf, tailBuf []byte) ([]byte, []byte, error) {
|
||||||
origDstBufLen := len(dstBuf)
|
|
||||||
if cap(dstBuf) < defaultBlockSize {
|
if cap(dstBuf) < defaultBlockSize {
|
||||||
dstBuf = bytesutil.Resize(dstBuf, defaultBlockSize)
|
dstBuf = bytesutil.Resize(dstBuf, defaultBlockSize)
|
||||||
}
|
}
|
||||||
|
@ -33,7 +32,7 @@ again:
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return dstBuf, tailBuf, fmt.Errorf("no forward progress made")
|
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,
|
// Missing newline in the end of stream. This is OK,
|
||||||
/// so suppress io.EOF for now. It will be returned during the next
|
/// so suppress io.EOF for now. It will be returned during the next
|
||||||
// call to ReadLinesBlock.
|
// call to ReadLinesBlock.
|
||||||
|
|
|
@ -79,6 +79,7 @@ func TestReadLineBlockSuccessSingleByteReader(t *testing.T) {
|
||||||
f("\nfoo", "", "")
|
f("\nfoo", "", "")
|
||||||
f("foo\nbar", "foo", "")
|
f("foo\nbar", "foo", "")
|
||||||
f("foo\nbar\nbaz", "foo", "")
|
f("foo\nbar\nbaz", "foo", "")
|
||||||
|
f("foo", "foo", "")
|
||||||
|
|
||||||
// The maximum line size
|
// The maximum line size
|
||||||
b := make([]byte, maxLineSize+10)
|
b := make([]byte, maxLineSize+10)
|
||||||
|
|
Loading…
Reference in a new issue