Skip to content

Commit a5bd770

Browse files
author
Dmitriy Matrenichev
committed
fix: retry with another upstream if the previous failed
Do not return response to the client if we got SERVFAIL or REFUSED, until we run out of upstreams. Fixes #9143 Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
1 parent 82e19f3 commit a5bd770

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

internal/pkg/dns/dns.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ func (h *Handler) ServeDNS(ctx context.Context, wrt dns.ResponseWriter, msg *dns
144144
break
145145
}
146146

147+
if resp != nil && (resp.Rcode == dns.RcodeServerFailure || resp.Rcode == dns.RcodeRefused) {
148+
continue
149+
}
150+
147151
if ctx.Err() != nil || err == nil {
148152
break
149153
}

internal/pkg/dns/dns_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,20 @@ func TestDNS(t *testing.T) {
6464
expectedCode: dnssrv.RcodeNameError,
6565
errCheck: check.NoError(),
6666
},
67+
{
68+
// The first one will return SERVFAIL and the second will return REFUSED. We should try both.
69+
name: `should return "refused"`,
70+
hostname: "dnssec-failed.org",
71+
nameservers: []string{"1.1.1.1", "ns-1098.awsdns-09.org."},
72+
expectedCode: dnssrv.RcodeRefused,
73+
errCheck: check.NoError(),
74+
},
6775
}
6876

6977
for _, test := range tests {
7078
t.Run(test.name, func(t *testing.T) {
7179
stop := newServer(t, test.nameservers...)
72-
defer stop()
80+
t.Cleanup(stop)
7381

7482
time.Sleep(10 * time.Millisecond)
7583

@@ -81,8 +89,6 @@ func TestDNS(t *testing.T) {
8189
}
8290

8391
t.Logf("r: %s", r)
84-
85-
stop()
8692
})
8793
}
8894
}

0 commit comments

Comments
 (0)