mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-30 15:22:07 +00:00
lib/protoparser: handle unexpected EOF error when parsing lines in prometheus exposition format (#4851)
Previously only io.EOF was handled, and io.ErrUnexpectedEOF was ignored, but it may happen if the client interrupts the connection. https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4817
This commit is contained in:
parent
54a67d439c
commit
9d39eec11e
2 changed files with 28 additions and 1 deletions
|
@ -93,7 +93,7 @@ again:
|
||||||
}
|
}
|
||||||
|
|
||||||
func isEOFLikeError(err error) bool {
|
func isEOFLikeError(err error) bool {
|
||||||
if errors.Is(err, io.EOF) {
|
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
s := err.Error()
|
s := err.Error()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -25,6 +26,20 @@ func TestReadLinesBlockFailure(t *testing.T) {
|
||||||
if _, _, err := ReadLinesBlock(fr, nil, nil); err == nil {
|
if _, _, err := ReadLinesBlock(fr, nil, nil); err == nil {
|
||||||
t.Fatalf("expecting non-nil error")
|
t.Fatalf("expecting non-nil error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
un := &unexpectedEOF{}
|
||||||
|
if _, _, err := ReadLinesBlock(un, nil, nil); err != nil {
|
||||||
|
if !errors.Is(err, io.EOF) {
|
||||||
|
t.Fatalf("get unexpected error, expecting io.EOF")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ef := eofErr{}
|
||||||
|
if _, _, err := ReadLinesBlock(ef, nil, nil); err != nil {
|
||||||
|
if !errors.Is(err, io.EOF) {
|
||||||
|
t.Fatalf("get unexpected error, expecting io.EOF")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// empty string
|
// empty string
|
||||||
|
@ -41,6 +56,18 @@ func (fr *failureReader) Read(p []byte) (int, error) {
|
||||||
return 0, fmt.Errorf("some error")
|
return 0, fmt.Errorf("some error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type unexpectedEOF struct{}
|
||||||
|
|
||||||
|
func (un unexpectedEOF) Read(p []byte) (int, error) {
|
||||||
|
return 0, io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
|
||||||
|
type eofErr struct{}
|
||||||
|
|
||||||
|
func (eo eofErr) Read(p []byte) (int, error) {
|
||||||
|
return 0, io.EOF
|
||||||
|
}
|
||||||
|
|
||||||
func TestReadLinesBlockMultiLinesSingleByteReader(t *testing.T) {
|
func TestReadLinesBlockMultiLinesSingleByteReader(t *testing.T) {
|
||||||
f := func(s string, linesExpected []string) {
|
f := func(s string, linesExpected []string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
Loading…
Reference in a new issue