getResponseFromUpstream: use timeout in conf

master
dingjun 2 years ago
parent b5fd23222e
commit 2d4867ee39

@ -10,6 +10,8 @@ import (
log "github.com/fangdingjun/go-log/v5" log "github.com/fangdingjun/go-log/v5"
) )
var cfg *conf
func main() { func main() {
var configfile string var configfile string
var logFileCount int var logFileCount int
@ -42,10 +44,12 @@ func main() {
log.Default.Level = lv log.Default.Level = lv
} }
cfg, err := loadConfig(configfile) _cfg, err := loadConfig(configfile)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
cfg = _cfg
if cfg.UpstreamTimeout == 0 { if cfg.UpstreamTimeout == 0 {
cfg.UpstreamTimeout = 5 cfg.UpstreamTimeout = 5
} }

@ -24,7 +24,7 @@ var dnsClientTLS *dns.Client
var dnsClientHTTPS *httpclient var dnsClientHTTPS *httpclient
func getResponseFromUpstream(msg *dns.Msg, upstreams []*url.URL) (*dns.Msg, error) { 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() defer cancel()
resch := make(chan *dns.Msg, len(upstreams)) resch := make(chan *dns.Msg, len(upstreams))

Loading…
Cancel
Save