From 72f566d145579776f8b460cb3a3240344cb241bb Mon Sep 17 00:00:00 2001 From: Simone Basso <bassosimone@gmail.com> Date: Tue, 3 Mar 2020 14:52:40 +0100 Subject: [PATCH] internal: remove the retrying dialer This is part of https://github.com/ooni/probe-engine/issues/302 --- go.mod | 1 - go.sum | 2 -- internal/httpx/httpx.go | 4 ++-- internal/netx/netx.go | 28 ---------------------------- internal/netx/netx_test.go | 18 ------------------ internal/retryx/retryx.go | 32 -------------------------------- 6 files changed, 2 insertions(+), 83 deletions(-) delete mode 100644 internal/netx/netx.go delete mode 100644 internal/netx/netx_test.go delete mode 100644 internal/retryx/retryx.go diff --git a/go.mod b/go.mod index 15f04ce2..a738d1ad 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,6 @@ require ( github.com/aristanetworks/goarista v0.0.0-20200214154357-2151774b0d85 // indirect github.com/armon/go-proxyproto v0.0.0-20180202201750-5b7edb60ff5f // indirect github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 // indirect - github.com/avast/retry-go v2.5.0+incompatible github.com/bifurcation/mint v0.0.0-20180306135233-198357931e61 // indirect github.com/boltdb/bolt v1.3.1 // indirect github.com/cognusion/go-cache-lru v0.0.0-20170419142635-f73e2280ecea // indirect diff --git a/go.sum b/go.sum index 6d6e1fbb..c9fbcfc7 100644 --- a/go.sum +++ b/go.sum @@ -73,8 +73,6 @@ github.com/armon/go-proxyproto v0.0.0-20180202201750-5b7edb60ff5f h1:SaJ6yqg936T github.com/armon/go-proxyproto v0.0.0-20180202201750-5b7edb60ff5f/go.mod h1:QmP9hvJ91BbJmGVGSbutW19IC0Q9phDCLGaomwTJbgU= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/avast/retry-go v2.5.0+incompatible h1:8SaFqliw34WeeaPs+GEtMMkiwEsC2S6+YyqnLqI55Ks= -github.com/avast/retry-go v2.5.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY= github.com/aws/aws-sdk-go v1.20.6/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= diff --git a/internal/httpx/httpx.go b/internal/httpx/httpx.go index 143e51c5..4f37bd78 100644 --- a/internal/httpx/httpx.go +++ b/internal/httpx/httpx.go @@ -8,11 +8,11 @@ import ( "io/ioutil" "net/http" "net/url" + "net" "time" "github.com/ooni/probe-engine/internal/httplog" "github.com/ooni/probe-engine/internal/httptracex" - "github.com/ooni/probe-engine/internal/netx" "github.com/ooni/probe-engine/log" ) @@ -28,7 +28,7 @@ func NewTransport( Proxy: proxy, // We use a custom dialer that retries failed // dialing attempts for extra robustness. - DialContext: (&netx.RetryingDialer{}).DialContext, + DialContext: (&net.Dialer{}).DialContext, TLSClientConfig: tlsConfig, // These are the same settings of Go stdlib. MaxIdleConns: 100, diff --git a/internal/netx/netx.go b/internal/netx/netx.go deleted file mode 100644 index 41bd3ccc..00000000 --- a/internal/netx/netx.go +++ /dev/null @@ -1,28 +0,0 @@ -// Package netx contains network extensions. -package netx - -import ( - "context" - "net" - - "github.com/ooni/probe-engine/internal/retryx" -) - -// RetryingDialer is a dialer where we retry dialing for -// a fixed number of attempts to increase reliability. -type RetryingDialer struct { - // Dialer is the embedded dialer. - net.Dialer -} - -// DialContext will dial for a specific network and address -// using the specified context. -func (rd *RetryingDialer) DialContext( - ctx context.Context, network, address string, -) (conn net.Conn, err error) { - err = retryx.Do(ctx, func() error { - conn, err = rd.Dialer.DialContext(ctx, network, address) - return err - }) - return -} diff --git a/internal/netx/netx_test.go b/internal/netx/netx_test.go deleted file mode 100644 index b678ffb3..00000000 --- a/internal/netx/netx_test.go +++ /dev/null @@ -1,18 +0,0 @@ -package netx_test - -import ( - "context" - "testing" - - "github.com/ooni/probe-engine/internal/netx" -) - -func TestDialContext(t *testing.T) { - conn, err := (&netx.RetryingDialer{}).DialContext( - context.Background(), "tcp", "www.google.com:80", - ) - if err != nil { - t.Fatal(err) - } - conn.Close() -} diff --git a/internal/retryx/retryx.go b/internal/retryx/retryx.go deleted file mode 100644 index f11d8aec..00000000 --- a/internal/retryx/retryx.go +++ /dev/null @@ -1,32 +0,0 @@ -// Package retryx helps to retry operations -package retryx - -import ( - "context" - "time" - - "github.com/avast/retry-go" -) - -var ( - // Attempts is the number of attempts - Attempts uint = 4 - - // Delay is the base interval for exponential backoff - Delay = 500 * time.Millisecond -) - -// Do retries fn for Attempts times using exponentiat backoff with -// a base interval equal to Delay. -func Do(ctx context.Context, fn func() error) error { - // Implementation note: not the optimal solution because the retry - // package will sleep and we would like instead to always be interruptible - // by the context. Yet, the maximum wait time with 4 attemtps and 500 - // millisecond is 1s, so it's not that bad. To be improved. - return retry.Do( - fn, retry.Attempts(Attempts), retry.Delay(Delay), - retry.RetryIf(func(err error) bool { - return ctx.Done() == nil - }), - ) -}