aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-04-01 16:18:21 +0100
committerGravatar GitHub <noreply@github.com> 2018-04-01 16:18:21 +0100
commit81348b420b0f312493ce889b40f65af65a0933d6 (patch)
treeb91c332e464fa45f6bdd1c22866686680e8b0900
parentf5435b38841c5865606aca7f1258c46bbf0e6027 (diff)
downloadcoredns-81348b420b0f312493ce889b40f65af65a0933d6.tar.gz
coredns-81348b420b0f312493ce889b40f65af65a0933d6.tar.zst
coredns-81348b420b0f312493ce889b40f65af65a0933d6.zip
plugin/forward: TCP conns can be closed (#1651)
* plugin/forward: TCP conns can be closed Only when we read and get a io.EOF we know the conn is closed (for TCP). If this is the case Dial (again) and retry. Note that this new connection can also be closed by the upstream, we may want to add a DialForceNew or something to get a new TCP connection.. Simular to #1624, *but* this is by (TCP) design. We also don't have to wait for a timeout which makes it easier to reason about. * Move to forward.go * doesnt need changing
-rw-r--r--plugin/forward/forward.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/plugin/forward/forward.go b/plugin/forward/forward.go
index 96b7e4c24..4c842f49e 100644
--- a/plugin/forward/forward.go
+++ b/plugin/forward/forward.go
@@ -7,6 +7,7 @@ package forward
import (
"crypto/tls"
"errors"
+ "io"
"time"
"github.com/coredns/coredns/plugin"
@@ -87,7 +88,19 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
ctx = ot.ContextWithSpan(ctx, child)
}
- ret, err := proxy.connect(ctx, state, f.forceTCP, true)
+ var (
+ ret *dns.Msg
+ err error
+ )
+ stop := false
+ for {
+ ret, err = proxy.connect(ctx, state, f.forceTCP, true)
+ if err != nil && err == io.EOF && !stop { // Remote side closed conn, can only happen with TCP.
+ stop = true
+ continue
+ }
+ break
+ }
if child != nil {
child.Finish()