From 24ffad74c10e885aa499a2b305585072f41e52cd Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 11 Jan 2021 12:50:10 +0200 Subject: [PATCH] all: use `net.Dial` instead of `fasthttp.Dial`, because `fasthttp.Dial` limits the number of concurrent dials to 1000 --- app/vmagent/remotewrite/statconn.go | 9 ++++----- docs/CHANGELOG.md | 2 ++ go.mod | 2 +- go.sum | 4 ++-- lib/proxy/proxy.go | 7 +++++-- vendor/github.com/VictoriaMetrics/fasthttp/tcpdialer.go | 5 +---- vendor/modules.txt | 2 +- 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/vmagent/remotewrite/statconn.go b/app/vmagent/remotewrite/statconn.go index 93cbf0a15..3c227dc19 100644 --- a/app/vmagent/remotewrite/statconn.go +++ b/app/vmagent/remotewrite/statconn.go @@ -5,9 +5,9 @@ import ( "net" "strings" "sync/atomic" + "time" "github.com/VictoriaMetrics/VictoriaMetrics/lib/netutil" - "github.com/VictoriaMetrics/fasthttp" "github.com/VictoriaMetrics/metrics" ) @@ -15,11 +15,10 @@ func statDial(network, addr string) (conn net.Conn, err error) { if !strings.HasPrefix(network, "tcp") { return nil, fmt.Errorf("unexpected network passed to statDial: %q; it must start from `tcp`", network) } - if netutil.TCP6Enabled() { - conn, err = fasthttp.DialDualStack(addr) - } else { - conn, err = fasthttp.Dial(addr) + if !netutil.TCP6Enabled() { + network = "tcp4" } + conn, err = net.DialTimeout(network, addr, 5*time.Second) dialsTotal.Inc() if err != nil { dialErrors.Inc() diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4ef7a1d49..11cb74908 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,8 @@ # tip +* BUGFIX: vmagent: prevent from `dialing to the given TCP address time out` error when scraping big number of unavailable targets. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/987 + * FEATURE: disable final merge for data for the previous month at the beginning of new month, since it may result in high disk IO and CPU usage. Final merge can be enabled by setting `-finalMergeDelay` command-line flag to positive duration. diff --git a/go.mod b/go.mod index 36ad3774b..6a1f20561 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( // Do not use the original github.com/valyala/fasthttp because of issues // like https://github.com/valyala/fasthttp/commit/996610f021ff45fdc98c2ce7884d5fa4e7f9199b - github.com/VictoriaMetrics/fasthttp v1.0.10 + github.com/VictoriaMetrics/fasthttp v1.0.11 github.com/VictoriaMetrics/metrics v1.12.3 github.com/VictoriaMetrics/metricsql v0.9.1 github.com/aws/aws-sdk-go v1.36.23 diff --git a/go.sum b/go.sum index fe7689199..1d48c9e86 100644 --- a/go.sum +++ b/go.sum @@ -41,8 +41,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/VictoriaMetrics/fastcache v1.5.7 h1:4y6y0G8PRzszQUYIQHHssv/jgPHAb5qQuuDNdCbyAgw= github.com/VictoriaMetrics/fastcache v1.5.7/go.mod h1:ptDBkNMQI4RtmVo8VS/XwRY6RoTu1dAWCbrk+6WsEM8= -github.com/VictoriaMetrics/fasthttp v1.0.10 h1:1UbdmWK59j7znylu55r0y66/zTaHbw+Xk+ObSGVywmE= -github.com/VictoriaMetrics/fasthttp v1.0.10/go.mod h1:3SeUL4zwB/p/a9aEeRc6gdlbrtNHXBJR6N376EgiSHU= +github.com/VictoriaMetrics/fasthttp v1.0.11 h1:6XOvE1pF/EhW8qoi7V5qJQJ2rhNV+UGrb1/a9vMbTiw= +github.com/VictoriaMetrics/fasthttp v1.0.11/go.mod h1:3SeUL4zwB/p/a9aEeRc6gdlbrtNHXBJR6N376EgiSHU= github.com/VictoriaMetrics/metrics v1.12.2/go.mod h1:Z1tSfPfngDn12bTfZSCqArT3OPY3u88J12hSoOhuiRE= github.com/VictoriaMetrics/metrics v1.12.3 h1:Fe6JHC6MSEKa+BtLhPN8WIvS+HKPzMc2evEpNeCGy7I= github.com/VictoriaMetrics/metrics v1.12.3/go.mod h1:Z1tSfPfngDn12bTfZSCqArT3OPY3u88J12hSoOhuiRE= diff --git a/lib/proxy/proxy.go b/lib/proxy/proxy.go index 82cb7b46a..bb3c339ef 100644 --- a/lib/proxy/proxy.go +++ b/lib/proxy/proxy.go @@ -7,6 +7,7 @@ import ( "fmt" "net" "net/url" + "time" "github.com/VictoriaMetrics/VictoriaMetrics/lib/netutil" "github.com/VictoriaMetrics/fasthttp" @@ -80,10 +81,12 @@ func (u *URL) NewDialFunc(tlsConfig *tls.Config) (fasthttp.DialFunc, error) { } func defaultDialFunc(addr string) (net.Conn, error) { + network := "tcp4" if netutil.TCP6Enabled() { - return fasthttp.DialDualStack(addr) + network = "tcp" } - return fasthttp.Dial(addr) + // Do not use fasthttp.Dial because of https://github.com/VictoriaMetrics/VictoriaMetrics/issues/987 + return net.DialTimeout(network, addr, 5*time.Second) } // sendConnectRequest sends CONNECT request to proxyConn for the given addr and authHeader and returns the established connection to dstAddr. diff --git a/vendor/github.com/VictoriaMetrics/fasthttp/tcpdialer.go b/vendor/github.com/VictoriaMetrics/fasthttp/tcpdialer.go index 8554306a9..e31fd7585 100644 --- a/vendor/github.com/VictoriaMetrics/fasthttp/tcpdialer.go +++ b/vendor/github.com/VictoriaMetrics/fasthttp/tcpdialer.go @@ -190,9 +190,6 @@ func (d *tcpDialer) NewDial(timeout time.Duration) DialFunc { if err == ErrDialTimeout { return nil, err } - if err, ok := err.(net.Error); ok && err.Timeout() { - return nil, err - } idx++ n-- } @@ -235,7 +232,7 @@ func tryDial(network string, addr *net.TCPAddr, deadline time.Time, concurrencyC ch := chv.(chan dialResult) go func() { var dr dialResult - dr.conn, dr.err = net.DialTimeout(network, addr.String(), timeout) + dr.conn, dr.err = net.DialTCP(network, nil, addr) ch <- dr <-concurrencyCh }() diff --git a/vendor/modules.txt b/vendor/modules.txt index 43fb09030..4c80dec6f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -10,7 +10,7 @@ cloud.google.com/go/internal/version cloud.google.com/go/storage # github.com/VictoriaMetrics/fastcache v1.5.7 github.com/VictoriaMetrics/fastcache -# github.com/VictoriaMetrics/fasthttp v1.0.10 +# github.com/VictoriaMetrics/fasthttp v1.0.11 github.com/VictoriaMetrics/fasthttp github.com/VictoriaMetrics/fasthttp/fasthttputil github.com/VictoriaMetrics/fasthttp/stackless