aboutsummaryrefslogtreecommitdiff
path: root/plugin/forward/persistent.go
diff options
context:
space:
mode:
authorGravatar Ruslan Drozhdzh <30860269+rdrozhdzh@users.noreply.github.com> 2018-04-06 15:41:48 +0300
committerGravatar Miek Gieben <miek@miek.nl> 2018-04-06 13:41:48 +0100
commite46ee9d9cc197d74dac0cb6e8432f83d4f43d1a6 (patch)
tree66ac38903d67d57f0a23552f0be7cea3bd3bdd93 /plugin/forward/persistent.go
parent848a5d7c7909afbc381a0708dc4893c28a1df61c (diff)
downloadcoredns-e46ee9d9cc197d74dac0cb6e8432f83d4f43d1a6.tar.gz
coredns-e46ee9d9cc197d74dac0cb6e8432f83d4f43d1a6.tar.zst
coredns-e46ee9d9cc197d74dac0cb6e8432f83d4f43d1a6.zip
plugin/forward: retry on cached tcp connection closed by peer (#1655)
* plugin/forward: retry on cached tcp connection closed by peer * fix linter warnings * fixed unit test * modify error message
Diffstat (limited to 'plugin/forward/persistent.go')
-rw-r--r--plugin/forward/persistent.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/plugin/forward/persistent.go b/plugin/forward/persistent.go
index 7bf083b49..6ea4d0371 100644
--- a/plugin/forward/persistent.go
+++ b/plugin/forward/persistent.go
@@ -16,8 +16,9 @@ type persistConn struct {
// connErr is used to communicate the connection manager.
type connErr struct {
- c *dns.Conn
- err error
+ c *dns.Conn
+ err error
+ cached bool
}
// transport hold the persistent cache.
@@ -86,7 +87,7 @@ Wait:
if time.Since(pc.used) < t.expire {
// Found one, remove from pool and return this conn.
t.conns[proto] = t.conns[proto][i+1:]
- t.ret <- connErr{pc.c, nil}
+ t.ret <- connErr{pc.c, nil, true}
continue Wait
}
// This conn has expired. Close it.
@@ -100,12 +101,12 @@ Wait:
go func() {
if proto != "tcp-tls" {
c, err := dns.DialTimeout(proto, t.addr, dialTimeout)
- t.ret <- connErr{c, err}
+ t.ret <- connErr{c, err, false}
return
}
c, err := dns.DialTimeoutWithTLS("tcp", t.addr, t.tlsConfig, dialTimeout)
- t.ret <- connErr{c, err}
+ t.ret <- connErr{c, err, false}
}()
case conn := <-t.yield:
@@ -139,7 +140,7 @@ Wait:
}
// Dial dials the address configured in transport, potentially reusing a connection or creating a new one.
-func (t *transport) Dial(proto string) (*dns.Conn, error) {
+func (t *transport) Dial(proto string) (*dns.Conn, bool, error) {
// If tls has been configured; use it.
if t.tlsConfig != nil {
proto = "tcp-tls"
@@ -147,12 +148,12 @@ func (t *transport) Dial(proto string) (*dns.Conn, error) {
t.dial <- proto
c := <-t.ret
- return c.c, c.err
+ return c.c, c.cached, c.err
}
// Yield return the connection to transport for reuse.
func (t *transport) Yield(c *dns.Conn) {
- t.yield <- connErr{c, nil}
+ t.yield <- connErr{c, nil, false}
}
// Stop stops the transport's connection manager.