mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/protoparser: move common code for detecting timeouts to ReadLinesBlockExt
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/696
This commit is contained in:
parent
4beab7ad39
commit
7554be172d
4 changed files with 20 additions and 37 deletions
|
@ -60,10 +60,14 @@ again:
|
|||
return dstBuf, tailBuf, nil
|
||||
}
|
||||
var ne net.Error
|
||||
if errors.As(err, &ne) && ne.Timeout() && fasttime.UnixTimestamp() == startTime {
|
||||
// Prevent from busy loop when timeout erorrs are returned immediately.
|
||||
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/696 .
|
||||
return dstBuf, tailBuf, fmt.Errorf("detected busy loop with repeated timeout error")
|
||||
if errors.As(err, &ne) && ne.Timeout() {
|
||||
if fasttime.UnixTimestamp() == startTime {
|
||||
// Prevent from busy loop when timeout erorrs are returned immediately.
|
||||
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/696 .
|
||||
return dstBuf, tailBuf, fmt.Errorf("detected busy loop with repeated timeout error")
|
||||
}
|
||||
// Return empty results for an ordinary timeout.
|
||||
return dstBuf, tailBuf, nil
|
||||
}
|
||||
return dstBuf, tailBuf, err
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package graphite
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -54,17 +53,11 @@ func (ctx *streamContext) Read(r io.Reader) bool {
|
|||
}
|
||||
ctx.reqBuf, ctx.tailBuf, ctx.err = common.ReadLinesBlock(r, ctx.reqBuf, ctx.tailBuf)
|
||||
if ctx.err != nil {
|
||||
var ne net.Error
|
||||
if errors.As(ctx.err, &ne) && ne.Timeout() {
|
||||
// Flush the read data on timeout and try reading again.
|
||||
ctx.err = nil
|
||||
} else {
|
||||
if ctx.err != io.EOF {
|
||||
readErrors.Inc()
|
||||
ctx.err = fmt.Errorf("cannot read graphite plaintext protocol data: %w", ctx.err)
|
||||
}
|
||||
return false
|
||||
if ctx.err != io.EOF {
|
||||
readErrors.Inc()
|
||||
ctx.err = fmt.Errorf("cannot read graphite plaintext protocol data: %w", ctx.err)
|
||||
}
|
||||
return false
|
||||
}
|
||||
ctx.Rows.Unmarshal(bytesutil.ToUnsafeString(ctx.reqBuf))
|
||||
rowsRead.Add(len(ctx.Rows.Rows))
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package opentsdb
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -53,17 +52,11 @@ func (ctx *streamContext) Read(r io.Reader) bool {
|
|||
}
|
||||
ctx.reqBuf, ctx.tailBuf, ctx.err = common.ReadLinesBlock(r, ctx.reqBuf, ctx.tailBuf)
|
||||
if ctx.err != nil {
|
||||
var ne net.Error
|
||||
if errors.As(ctx.err, &ne) && ne.Timeout() {
|
||||
// Flush the read data on timeout and try reading again.
|
||||
ctx.err = nil
|
||||
} else {
|
||||
if ctx.err != io.EOF {
|
||||
readErrors.Inc()
|
||||
ctx.err = fmt.Errorf("cannot read OpenTSDB put protocol data: %w", ctx.err)
|
||||
}
|
||||
return false
|
||||
if ctx.err != io.EOF {
|
||||
readErrors.Inc()
|
||||
ctx.err = fmt.Errorf("cannot read OpenTSDB put protocol data: %w", ctx.err)
|
||||
}
|
||||
return false
|
||||
}
|
||||
ctx.Rows.Unmarshal(bytesutil.ToUnsafeString(ctx.reqBuf))
|
||||
rowsRead.Add(len(ctx.Rows.Rows))
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package prometheus
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
|
@ -54,17 +53,11 @@ func (ctx *streamContext) Read(r io.Reader) bool {
|
|||
}
|
||||
ctx.reqBuf, ctx.tailBuf, ctx.err = common.ReadLinesBlock(r, ctx.reqBuf, ctx.tailBuf)
|
||||
if ctx.err != nil {
|
||||
var ne net.Error
|
||||
if errors.As(ctx.err, &ne) && ne.Timeout() {
|
||||
// Flush the read data on timeout and try reading again.
|
||||
ctx.err = nil
|
||||
} else {
|
||||
if ctx.err != io.EOF {
|
||||
readErrors.Inc()
|
||||
ctx.err = fmt.Errorf("cannot read Prometheus exposition data: %w", ctx.err)
|
||||
}
|
||||
return false
|
||||
if ctx.err != io.EOF {
|
||||
readErrors.Inc()
|
||||
ctx.err = fmt.Errorf("cannot read Prometheus exposition data: %w", ctx.err)
|
||||
}
|
||||
return false
|
||||
}
|
||||
ctx.Rows.Unmarshal(bytesutil.ToUnsafeString(ctx.reqBuf))
|
||||
rowsRead.Add(len(ctx.Rows.Rows))
|
||||
|
|
Loading…
Reference in a new issue