mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/netutil: ignore arificial timeout generated by net/http.Server
This prevents from the inflated vm_tcplistener_read_timeouts_total counter
This commit is contained in:
parent
298aab3f54
commit
0f01eea4e9
1 changed files with 8 additions and 1 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fasttime"
|
||||||
"github.com/VictoriaMetrics/metrics"
|
"github.com/VictoriaMetrics/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -54,13 +55,19 @@ type statConn struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *statConn) Read(p []byte) (int, error) {
|
func (sc *statConn) Read(p []byte) (int, error) {
|
||||||
|
startTime := fasttime.UnixTimestamp()
|
||||||
n, err := sc.Conn.Read(p)
|
n, err := sc.Conn.Read(p)
|
||||||
sc.cm.readCalls.Inc()
|
sc.cm.readCalls.Inc()
|
||||||
sc.cm.readBytes.Add(n)
|
sc.cm.readBytes.Add(n)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
var ne net.Error
|
var ne net.Error
|
||||||
if errors.As(err, &ne) && ne.Timeout() {
|
if errors.As(err, &ne) && ne.Timeout() {
|
||||||
|
if fasttime.UnixTimestamp()-startTime <= 1 {
|
||||||
|
// Ignore artificial timeout generated by net/http.Server
|
||||||
|
// See https://cs.opensource.google/go/go/+/refs/tags/go1.20.5:src/net/http/server.go;l=701
|
||||||
|
} else {
|
||||||
sc.cm.readTimeouts.Inc()
|
sc.cm.readTimeouts.Inc()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sc.cm.readErrors.Inc()
|
sc.cm.readErrors.Inc()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue