diff options
-rw-r--r-- | plugin/forward/README.md | 5 | ||||
-rw-r--r-- | plugin/forward/connect.go | 4 | ||||
-rw-r--r-- | plugin/forward/forward.go | 2 | ||||
-rw-r--r-- | plugin/forward/proxy.go | 7 | ||||
-rw-r--r-- | plugin/forward/proxy_test.go | 2 |
5 files changed, 10 insertions, 10 deletions
diff --git a/plugin/forward/README.md b/plugin/forward/README.md index d87ba2eec..d0cf89e88 100644 --- a/plugin/forward/README.md +++ b/plugin/forward/README.md @@ -83,8 +83,9 @@ Also note the TLS config is "global" for the whole forwarding proxy if you need `tls-name` for different upstreams you're out of luck. On each endpoint, the timeouts of the communication are set by default and automatically tuned depending early results. -- dialTimeout by default is 30 sec, and can decrease automatically down to 100ms -- readTimeout by default is 2 sec, and can decrease automatically down to 10ms + +* dialTimeout by default is 30 sec, and can decrease automatically down to 100ms +* readTimeout by default is 2 sec, and can decrease automatically down to 200ms ## Metrics diff --git a/plugin/forward/connect.go b/plugin/forward/connect.go index fe6313e0e..3259fda5e 100644 --- a/plugin/forward/connect.go +++ b/plugin/forward/connect.go @@ -97,7 +97,7 @@ func (p *Proxy) Connect(ctx context.Context, state request.Request, forceTCP, me conn.UDPSize = 512 } - conn.SetWriteDeadline(time.Now().Add(timeout)) + conn.SetWriteDeadline(time.Now().Add(maxTimeout)) reqTime := time.Now() if err := conn.WriteMsg(state.Req); err != nil { conn.Close() // not giving it back @@ -110,7 +110,7 @@ func (p *Proxy) Connect(ctx context.Context, state request.Request, forceTCP, me conn.SetReadDeadline(time.Now().Add(p.readTimeout())) ret, err := conn.ReadMsg() if err != nil { - p.updateRtt(timeout) + p.updateRtt(maxTimeout) conn.Close() // not giving it back if err == io.EOF && cached { return nil, ErrCachedClosed diff --git a/plugin/forward/forward.go b/plugin/forward/forward.go index ce81392f5..92bf14bb6 100644 --- a/plugin/forward/forward.go +++ b/plugin/forward/forward.go @@ -39,7 +39,7 @@ type Forward struct { // New returns a new Forward. func New() *Forward { - f := &Forward{maxfails: 2, tlsConfig: new(tls.Config), expire: defaultExpire, p: new(random), from: ".", hcInterval: hcDuration} + f := &Forward{maxfails: 2, tlsConfig: new(tls.Config), expire: defaultExpire, p: new(random), from: ".", hcInterval: hcInterval} return f } diff --git a/plugin/forward/proxy.go b/plugin/forward/proxy.go index a1fa7e6ae..91d7c38b1 100644 --- a/plugin/forward/proxy.go +++ b/plugin/forward/proxy.go @@ -34,7 +34,7 @@ func NewProxy(addr string, tlsConfig *tls.Config) *Proxy { fails: 0, probe: up.New(), transport: newTransport(addr, tlsConfig), - avgRtt: int64(timeout / 2), + avgRtt: int64(maxTimeout / 2), } p.client = dnsClient(tlsConfig) runtime.SetFinalizer(p, (*Proxy).finalizer) @@ -106,8 +106,7 @@ func (p *Proxy) start(duration time.Duration) { } const ( - timeout = 2 * time.Second maxTimeout = 2 * time.Second - minTimeout = 10 * time.Millisecond - hcDuration = 500 * time.Millisecond + minTimeout = 200 * time.Millisecond + hcInterval = 500 * time.Millisecond ) diff --git a/plugin/forward/proxy_test.go b/plugin/forward/proxy_test.go index 234458b63..01e8ef6fd 100644 --- a/plugin/forward/proxy_test.go +++ b/plugin/forward/proxy_test.go @@ -27,7 +27,7 @@ func TestProxyClose(t *testing.T) { for i := 0; i < 100; i++ { p := NewProxy(s.Addr, nil) - p.start(hcDuration) + p.start(hcInterval) go func() { p.Connect(ctx, state, false, false) }() go func() { p.Connect(ctx, state, true, false) }() |