diff --git a/main.go b/main.go index 5427fc5..36e4ece 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,8 @@ import ( log "github.com/fangdingjun/go-log/v5" ) +var cfg *conf + func main() { var configfile string var logFileCount int @@ -42,10 +44,12 @@ func main() { log.Default.Level = lv } - cfg, err := loadConfig(configfile) + _cfg, err := loadConfig(configfile) if err != nil { log.Fatal(err) } + + cfg = _cfg if cfg.UpstreamTimeout == 0 { cfg.UpstreamTimeout = 5 } diff --git a/upstream.go b/upstream.go index 83c1214..7bb3f02 100644 --- a/upstream.go +++ b/upstream.go @@ -24,7 +24,7 @@ var dnsClientTLS *dns.Client var dnsClientHTTPS *httpclient func getResponseFromUpstream(msg *dns.Msg, upstreams []*url.URL) (*dns.Msg, error) { - ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(cfg.UpstreamTimeout+1)*time.Second) defer cancel() resch := make(chan *dns.Msg, len(upstreams))