plugin/forward: add query timeout (#1665)

This commit is contained in:
Ruslan Drozhdzh
2018-04-11 09:53:08 +03:00
committed by Miek Gieben
parent ccfe691b95
commit a0f294e550
2 changed files with 62 additions and 3 deletions

View File

@@ -67,8 +67,19 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
var span, child ot.Span
var upstreamErr error
span = ot.SpanFromContext(ctx)
i := 0
list := f.list()
deadline := time.Now().Add(defaultTimeout)
for _, proxy := range f.list() {
for time.Now().Before(deadline) {
if i >= len(list) {
// reached the end of list, reset to begin
i = 0
fails = 0
}
proxy := list[i]
i++
if proxy.Down(f.maxfails) {
fails++
if fails < len(f.proxies) {
@@ -183,3 +194,5 @@ const (
randomPolicy policy = iota
roundRobinPolicy
)
const defaultTimeout = 5 * time.Second