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"
)
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
}

@ -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))

Loading…
Cancel
Save