From dc19c58c54821f3159cbaf73a9ac5b3979cd362a Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Fri, 15 Jun 2018 09:42:41 +0800 Subject: [PATCH] fix crash issue when unknown network type --- handler.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/handler.go b/handler.go index ec54514..19a1ee1 100644 --- a/handler.go +++ b/handler.go @@ -98,21 +98,22 @@ func (h *dnsHandler) queryUpstream(r *dns.Msg, srv addr, ch chan *dns.Msg) { srv.Port) m, _, err = h.httpscf.Exchange(r, srv.Host) default: - // ignore + err = fmt.Errorf("not supported type %s", srv.Network) } - if err == nil { - select { - case ch <- m: - default: - } - } else { + if err != nil { log.Errorf("%s", err) + return + } + + select { + case ch <- m: + default: } } func (h *dnsHandler) getAnswerFromUpstream(r *dns.Msg, servers []addr) (*dns.Msg, error) { - ch := make(chan *dns.Msg, 5) + ch := make(chan *dns.Msg, len(servers)) for _, srv := range servers { go func(a addr) { h.queryUpstream(r, a, ch)