plugin/forward: remove dynamic read timeout (#2319)

* plugin/forward: remove dynamic read timeout

We care about an upstream being there, so we still have a dynamic dial
time out (by way higher then 200ms) of 1s; this should be fairly stable
for an upstream. The read timeout if more variable because of cached and
non cached responses. As such remove his logic entirely.

Drop to 2s read timeout.

Fixes #2306

Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben
2018-11-20 08:48:56 +01:00
committed by GitHub
parent e94ce7a12a
commit a1d92c51cd
5 changed files with 15 additions and 26 deletions

View File

@@ -69,14 +69,6 @@ func (t *Transport) Dial(proto string) (*dns.Conn, bool, error) {
return conn, false, err
}
func (p *Proxy) readTimeout() time.Duration {
return limitTimeout(&p.avgRtt, minTimeout, maxTimeout)
}
func (p *Proxy) updateRtt(newRtt time.Duration) {
averageTimeout(&p.avgRtt, newRtt, cumulativeAvgWeight)
}
// Connect selects an upstream, sends the request and waits for a response.
func (p *Proxy) Connect(ctx context.Context, state request.Request, opts options) (*dns.Msg, error) {
start := time.Now()
@@ -103,7 +95,6 @@ func (p *Proxy) Connect(ctx context.Context, state request.Request, opts options
}
conn.SetWriteDeadline(time.Now().Add(maxTimeout))
reqTime := time.Now()
if err := conn.WriteMsg(state.Req); err != nil {
conn.Close() // not giving it back
if err == io.EOF && cached {
@@ -112,10 +103,9 @@ func (p *Proxy) Connect(ctx context.Context, state request.Request, opts options
return nil, err
}
conn.SetReadDeadline(time.Now().Add(p.readTimeout()))
conn.SetReadDeadline(time.Now().Add(readTimeout))
ret, err := conn.ReadMsg()
if err != nil {
p.updateRtt(maxTimeout)
conn.Close() // not giving it back
if err == io.EOF && cached {
return nil, ErrCachedClosed
@@ -123,8 +113,6 @@ func (p *Proxy) Connect(ctx context.Context, state request.Request, opts options
return ret, err
}
p.updateRtt(time.Since(reqTime))
p.transport.Yield(conn)
rc, ok := dns.RcodeToString[ret.Rcode]