diff --git a/dns/resolver.go b/dns/resolver.go index 50e0c3d..75c907c 100644 --- a/dns/resolver.go +++ b/dns/resolver.go @@ -141,7 +141,11 @@ func (r *Resolver) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Msg, e msg = cache.(*D.Msg).Copy() if expireTime.Before(now) { setMsgTTL(msg, uint32(1)) // Continue fetch - go r.exchangeWithoutCache(ctx, m) + go func() { + ctx, cancel := context.WithTimeout(context.Background(), resolver.DefaultDNSTimeout) + r.exchangeWithoutCache(ctx, m) + cancel() + }() } else { // updating TTL by subtracting common delta time from each DNS record updateMsgTTL(msg, uint32(time.Until(expireTime).Seconds()))