mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 00:34:24 -04:00
plugin/forward: add query timeout (#1665)
This commit is contained in:
committed by
Miek Gieben
parent
ccfe691b95
commit
a0f294e550
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user