From 1a40767cb7f5e435ef6a9812276cafed195ab6c3 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Wed, 8 Mar 2023 09:01:42 +0700 Subject: [PATCH] Use upstream timeout when querying bootstrap IP --- config.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index 45563fe..1c9094f 100644 --- a/config.go +++ b/config.go @@ -182,6 +182,9 @@ func (uc *UpstreamConfig) SetupTransport() { // SetupBootstrapIP manually find all available IPs of the upstream. func (uc *UpstreamConfig) SetupBootstrapIP() error { + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(uc.Timeout)*time.Second) + defer cancel() + uc.mu.Lock() defer uc.mu.Unlock() @@ -193,7 +196,7 @@ func (uc *UpstreamConfig) SetupBootstrapIP() error { } m.SetQuestion(uc.Domain+".", dnsType) m.RecursionDesired = true - r, _, err := c.Exchange(m, net.JoinHostPort(bootstrapDNS, "53")) + r, _, err := c.ExchangeContext(ctx, m, net.JoinHostPort(bootstrapDNS, "53")) if err != nil { ProxyLog.Error().Err(err).Msgf("could not resolve domain %s for upstream", uc.Domain) return err