From 0f01eea4e9c75fc9c062ddaa8c9b731405a9c437 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 16 Jun 2023 22:50:30 -0700 Subject: [PATCH] lib/netutil: ignore arificial timeout generated by net/http.Server This prevents from the inflated vm_tcplistener_read_timeouts_total counter --- lib/netutil/conn.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/netutil/conn.go b/lib/netutil/conn.go index 18b325129..9db9b469a 100644 --- a/lib/netutil/conn.go +++ b/lib/netutil/conn.go @@ -7,6 +7,7 @@ import ( "net" "sync/atomic" + "github.com/VictoriaMetrics/VictoriaMetrics/lib/fasttime" "github.com/VictoriaMetrics/metrics" ) @@ -54,13 +55,19 @@ type statConn struct { } func (sc *statConn) Read(p []byte) (int, error) { + startTime := fasttime.UnixTimestamp() n, err := sc.Conn.Read(p) sc.cm.readCalls.Inc() sc.cm.readBytes.Add(n) if err != nil && err != io.EOF { var ne net.Error if errors.As(err, &ne) && ne.Timeout() { - sc.cm.readTimeouts.Inc() + 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() + } } else { sc.cm.readErrors.Inc() }