Skip to content

Commit

Permalink
Merge pull request #37 from xonvanetta/master
Browse files Browse the repository at this point in the history
fix: return last err from processClient
  • Loading branch information
denis-tingaikin authored Oct 17, 2021
2 parents f19ab01 + 26f636e commit 818e324
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions fanout.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package fanout
import (
"context"
"crypto/tls"
"errors"
"time"

"github.com/coredns/coredns/plugin"
Expand All @@ -29,6 +28,7 @@ import (
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
"github.com/pkg/errors"
)

var log = clog.NewWithPlugin("fanout")
Expand Down Expand Up @@ -158,17 +158,19 @@ func (f *Fanout) match(state *request.Request) bool {

func (f *Fanout) processClient(ctx context.Context, c Client, r *request.Request) *response {
start := time.Now()
var err error
for j := 0; j < f.attempts || f.attempts == 0; <-time.After(attemptDelay) {
if ctx.Err() != nil {
return &response{client: c, response: nil, start: start, err: ctx.Err()}
}
msg, err := c.Request(ctx, r)
var msg *dns.Msg
msg, err = c.Request(ctx, r)
if err == nil {
return &response{client: c, response: msg, start: start, err: err}
}
if f.attempts != 0 {
j++
}
}
return &response{client: c, response: nil, start: start, err: errors.New("attempt limit has been reached")}
return &response{client: c, response: nil, start: start, err: errors.Wrapf(err, "attempt limit has been reached, last err")}
}

0 comments on commit 818e324

Please sign in to comment.