diff --git a/dnsfilter/dnsfilter.go b/dnsfilter/dnsfilter.go index f18bd8c7..dcecbccc 100644 --- a/dnsfilter/dnsfilter.go +++ b/dnsfilter/dnsfilter.go @@ -15,6 +15,8 @@ import ( "sync/atomic" "time" + "github.com/joomcode/errorx" + "github.com/AdguardTeam/dnsproxy/upstream" "github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/urlfilter" @@ -674,15 +676,16 @@ func (d *Dnsfilter) createCustomDialContext(resolverAddr string) dialFunctionTyp return nil, e } - var firstErr error - firstErr = nil + if len(addrs) == 0 { + return nil, fmt.Errorf("couldn't lookup host: %s", host) + } + + var dialErrs []error for _, a := range addrs { addr = fmt.Sprintf("%s:%s", a.String(), port) con, err := dialer.DialContext(ctx, network, addr) if err != nil { - if firstErr == nil { - firstErr = err - } + dialErrs = append(dialErrs, err) continue } @@ -692,7 +695,7 @@ func (d *Dnsfilter) createCustomDialContext(resolverAddr string) dialFunctionTyp return con, err } - return nil, firstErr + return nil, errorx.DecorateMany(fmt.Sprintf("couldn't dial to %s", addr), dialErrs...) } } diff --git a/home/config.go b/home/config.go index 7d9a509e..8744c842 100644 --- a/home/config.go +++ b/home/config.go @@ -126,6 +126,7 @@ type tlsConfig struct { } // initialize to default values, will be changed later when reading config or parsing command line +// TODO: Get rid of global variables var config = configuration{ ourConfigFilename: "AdGuardHome.yaml", BindPort: 3000, diff --git a/home/helpers.go b/home/helpers.go index 68fbd7a3..e1500311 100644 --- a/home/helpers.go +++ b/home/helpers.go @@ -338,20 +338,21 @@ func customDialContext(ctx context.Context, network, addr string) (net.Conn, err return nil, e } - var firstErr error - firstErr = nil + if len(addrs) == 0 { + return nil, fmt.Errorf("couldn't lookup host: %s", host) + } + + var dialErrs []error for _, a := range addrs { addr = net.JoinHostPort(a.String(), port) con, err := dialer.DialContext(ctx, network, addr) if err != nil { - if firstErr == nil { - firstErr = err - } + dialErrs = append(dialErrs, err) continue } return con, err } - return nil, firstErr + return nil, errorx.DecorateMany(fmt.Sprintf("couldn't dial to %s", addr), dialErrs...) } // check if error is "address already in use"