From 81348b420b0f312493ce889b40f65af65a0933d6 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sun, 1 Apr 2018 16:18:21 +0100 Subject: 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 --- plugin/forward/forward.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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() -- cgit v1.2.3